diff -Nru cargo-0.47.0/ARCHITECTURE.md cargo-0.51.0/ARCHITECTURE.md
--- cargo-0.47.0/ARCHITECTURE.md 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/ARCHITECTURE.md 1970-01-01 00:00:00.000000000 +0000
@@ -1,150 +0,0 @@
-# Cargo Architecture
-
-This document gives a high level overview of Cargo internals. You may
-find it useful if you want to contribute to Cargo or if you are
-interested in the inner workings of Cargo.
-
-The purpose of Cargo is to formalize a canonical Rust workflow, by automating
-the standard tasks associated with distributing software. Cargo simplifies
-structuring a new project, adding dependencies, writing and running unit tests,
-and more.
-
-
-## Subcommands
-
-Cargo is a single binary composed of a set of [`clap`] subcommands. All subcommands live in
-`src/bin/cargo/commands` directory. `src/bin/cargo/main.rs` is the entry point.
-
-Each subcommand, such as [`src/bin/cargo/commands/build.rs`], has its own API
-interface, similarly to Git's, parsing command line options, reading the
-configuration files, discovering the Cargo project in the current directory and
-delegating the actual implementation to one
-of the functions in [`src/cargo/ops/mod.rs`]. This short file is a good
-place to find out about most of the things that Cargo can do.
-Subcommands are designed to pipe to one another, and custom subcommands make
-Cargo easy to extend and attach tools to.
-
-[`clap`]: https://clap.rs/
-[`src/bin/cargo/commands/build.rs`]: src/bin/cargo/commands/build.rs
-[`src/cargo/ops/mod.rs`]: src/cargo/ops/mod.rs
-
-
-## Important Data Structures
-
-There are some important data structures which are used throughout
-Cargo.
-
-[`Config`] is available almost everywhere and holds "global"
-information, such as `CARGO_HOME` or configuration from
-`.cargo/config` files. The [`shell`] method of [`Config`] is the entry
-point for printing status messages and other info to the console.
-
-[`Workspace`] is the description of the workspace for the current
-working directory. Each workspace contains at least one
-[`Package`]. Each package corresponds to a single `Cargo.toml`, and may
-define several [`Target`]s, such as the library, binaries, integration
-test or examples. Targets are crates (each target defines a crate
-root, like `src/lib.rs` or `examples/foo.rs`) and are what is actually
-compiled by `rustc`.
-
-A typical package defines the single library target and several
-auxiliary ones. Packages are a unit of dependency in Cargo, and when
-package `foo` depends on package `bar`, that means that each target
-from `foo` needs the library target from `bar`.
-
-[`PackageId`] is the unique identifier of a (possibly remote)
-package. It consist of three components: name, version and source
-id. Source is the place where the source code for package comes
-from. Typical sources are crates.io, a git repository or a folder on
-the local hard drive.
-
-[`Resolve`] is the representation of a directed acyclic graph of package
-dependencies, which uses [`PackageId`]s for nodes. This is the data
-structure that is saved to the lock file. If there is no lock file,
-Cargo constructs a resolve by finding a graph of packages which
-matches declared dependency specification according to semver.
-
-[`Config`]: https://docs.rs/cargo/latest/cargo/util/config/struct.Config.html
-[`shell`]: https://docs.rs/cargo/latest/cargo/util/config/struct.Config.html#method.shell
-[`Workspace`]: https://docs.rs/cargo/latest/cargo/core/struct.Workspace.html
-[`Package`]: https://docs.rs/cargo/latest/cargo/core/package/struct.Package.html
-[`Target`]: https://docs.rs/cargo/latest/cargo/core/manifest/struct.Target.html
-[`PackageId`]: https://docs.rs/cargo/latest/cargo/core/package_id/struct.PackageId.html
-[`Resolve`]: https://docs.rs/cargo/latest/cargo/core/struct.Resolve.html
-
-
-## Persistence
-
-Cargo is a non-daemon command line application, which means that all
-the information used by Cargo must be persisted on the hard drive. The
-main sources of information are `Cargo.toml` and `Cargo.lock` files,
-`.cargo/config` configuration files and the globally shared registry
-of packages downloaded from crates.io, usually located at
-`~/.cargo/registry`. See [`src/cargo/sources/registry`] for the specifics of
-the registry storage format.
-
-[`src/cargo/sources/registry`]: src/cargo/sources/registry
-
-
-## Concurrency
-
-Cargo is mostly single threaded. The only concurrency inside a single
-instance of Cargo happens during compilation, when several instances
-of `rustc` are invoked in parallel to build independent
-targets. However there can be several different instances of Cargo
-process running concurrently on the system. Cargo guarantees that this
-is always safe by using file locks when accessing potentially shared
-data like the registry or the target directory.
-
-
-## Tests
-
-Cargo has an impressive test suite located in the `tests` folder. Most
-of the test are integration: a project structure with `Cargo.toml` and
-rust source code is created in a temporary directory, `cargo` binary
-is invoked via `std::process::Command` and then stdout and stderr are
-verified against the expected output. To simplify testing, several
-macros of the form `[MACRO]` are used in the expected output. For
-example, `[..]` matches any string.
-
-To see stdout and stderr streams of the subordinate process, add `.stream()`
-call to the built-up `Execs`:
-
-```rust
-// Before
-p.cargo("run").run();
-
-// After
-p.cargo("run").stream().run();
-```
-
-Alternatively to build and run a custom version of cargo simply run `cargo build`
-and execute `target/debug/cargo`. Note that `+nightly`/`+stable` (and variants),
-being [rustup] features, won't work when executing the locally
-built cargo binary directly, you have to instead build with `cargo +nightly build`
-and run with `rustup run` (e.g `rustup run nightly
-/target/debug/cargo ..`) (or set the `RUSTC` env var to point
-to nightly rustc).
-
-[rustup]: https://rustup.rs/
-
-
-## Logging
-
-Cargo uses [`env_logger`], so you can set
-`CARGO_LOG` environment variable to get the logs. This is useful both for diagnosing
-bugs in stable Cargo and for local development. Cargo also has internal hierarchical
-profiling infrastructure, which is activated via `CARGO_PROFILE` variable
-
-```
-# Outputs all logs with levels debug and higher
-$ CARGO_LOG=debug cargo generate-lockfile
-
-# Don't forget that you can filter by module as well
-$ CARGO_LOG=cargo::core::resolver=trace cargo generate-lockfile
-
-# Output first three levels of profiling info
-$ CARGO_PROFILE=3 cargo generate-lockfile
-```
-
-[`env_logger`]: https://docs.rs/env_logger/*/env_logger/
diff -Nru cargo-0.47.0/azure-pipelines.yml cargo-0.51.0/azure-pipelines.yml
--- cargo-0.47.0/azure-pipelines.yml 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/azure-pipelines.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,118 +0,0 @@
-trigger:
- branches:
- include:
- - '*'
- exclude:
- - master
-
-jobs:
-- job: Linux
- pool:
- vmImage: ubuntu-16.04
- steps:
- - template: ci/azure-test-all.yml
- strategy:
- matrix:
- stable:
- TOOLCHAIN: stable
- beta:
- TOOLCHAIN: beta
- nightly:
- TOOLCHAIN: nightly
- variables:
- OTHER_TARGET: i686-unknown-linux-gnu
-
-- job: macOS
- pool:
- vmImage: macos-10.15
- steps:
- - template: ci/azure-test-all.yml
- variables:
- TOOLCHAIN: stable
- OTHER_TARGET: x86_64-apple-ios
-
-- job: Windows
- pool:
- vmImage: windows-2019
- steps:
- - template: ci/azure-test-all.yml
- strategy:
- matrix:
- x86_64-msvc:
- TOOLCHAIN: stable-x86_64-pc-windows-msvc
- OTHER_TARGET: i686-pc-windows-msvc
- x86_64-gnu:
- TOOLCHAIN: nightly-x86_64-pc-windows-gnu
- OTHER_TARGET: i686-pc-windows-gnu
-
-- job: rustfmt
- pool:
- vmImage: ubuntu-16.04
- steps:
- - template: ci/azure-install-rust.yml
- - bash: rustup component add rustfmt
- displayName: "Install rustfmt"
- - bash: cargo fmt --all -- --check
- displayName: "Check rustfmt (cargo)"
- - bash: cd crates/cargo-test-macro && cargo fmt --all -- --check
- displayName: "Check rustfmt (cargo-test-macro)"
- - bash: cd crates/cargo-test-support && cargo fmt --all -- --check
- displayName: "Check rustfmt (cargo-test-support)"
- - bash: cd crates/crates-io && cargo fmt --all -- --check
- displayName: "Check rustfmt (crates-io)"
- - bash: cd crates/resolver-tests && cargo fmt --all -- --check
- displayName: "Check rustfmt (resolver-tests)"
- - bash: cd crates/cargo-platform && cargo fmt --all -- --check
- displayName: "Check rustfmt (cargo-platform)"
- variables:
- TOOLCHAIN: stable
-
-- job: resolver
- pool:
- vmImage: ubuntu-16.04
- steps:
- - template: ci/azure-install-rust.yml
- - bash: cargo test --manifest-path crates/resolver-tests/Cargo.toml
- displayName: "Resolver tests"
- variables:
- TOOLCHAIN: stable
-
-- job: build_std
- pool:
- vmImage: ubuntu-16.04
- steps:
- - template: ci/azure-install-rust.yml
- - bash: rustup component add rust-src
- displayName: "Install rust-src"
- - bash: cargo build
- - bash: cargo test --test build-std
- displayName: "tests"
- variables:
- TOOLCHAIN: nightly
- CARGO_RUN_BUILD_STD_TESTS: 1
-
-- job: docs
- pool:
- vmImage: ubuntu-16.04
- variables:
- TOOLCHAIN: nightly
- steps:
- - template: ci/azure-install-rust.yml
- - bash: |
- set -e
- mkdir mdbook
- curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.3.7/mdbook-v0.3.7-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
- echo "##vso[task.prependpath]`pwd`/mdbook"
- displayName: "Install mdbook"
- - bash: cargo doc --no-deps
- displayName: "Build documentation"
- - bash: cd src/doc && mdbook build --dest-dir ../../target/doc
- displayName: "Build mdbook documentation"
- - bash: |
- set -e
- rustup component add rust-docs
- cd src/doc
- curl -sSLo linkcheck.sh \
- https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
- sh linkcheck.sh --all cargo
- displayName: "Check for broken links"
diff -Nru cargo-0.47.0/build.rs cargo-0.51.0/build.rs
--- cargo-0.47.0/build.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/build.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,39 @@
+use flate2::{Compression, GzBuilder};
+use std::ffi::OsStr;
+use std::fs;
+use std::path::Path;
+
+fn main() {
+ compress_man();
+}
+
+fn compress_man() {
+ let out_path = Path::new(&std::env::var("OUT_DIR").unwrap()).join("man.tgz");
+ let dst = fs::File::create(out_path).unwrap();
+ let encoder = GzBuilder::new()
+ .filename("man.tar")
+ .write(dst, Compression::best());
+ let mut ar = tar::Builder::new(encoder);
+ ar.mode(tar::HeaderMode::Deterministic);
+
+ let mut add_files = |dir, extension| {
+ let mut files = fs::read_dir(dir)
+ .unwrap()
+ .map(|e| e.unwrap().path())
+ .collect::>();
+ files.sort();
+ for path in files {
+ if path.extension() != Some(extension) {
+ continue;
+ }
+ println!("cargo:rerun-if-changed={}", path.display());
+ ar.append_path_with_name(&path, path.file_name().unwrap())
+ .unwrap();
+ }
+ };
+
+ add_files(Path::new("src/etc/man"), OsStr::new("1"));
+ add_files(Path::new("src/doc/man/generated_txt"), OsStr::new("txt"));
+ let encoder = ar.into_inner().unwrap();
+ encoder.finish().unwrap();
+}
diff -Nru cargo-0.47.0/Cargo.toml cargo-0.51.0/Cargo.toml
--- cargo-0.47.0/Cargo.toml 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/Cargo.toml 2021-02-04 15:18:32.000000000 +0000
@@ -1,6 +1,6 @@
[package]
name = "cargo"
-version = "0.47.0"
+version = "0.51.0"
edition = "2018"
authors = ["Yehuda Katz ",
"Carl Lerche ",
@@ -23,17 +23,17 @@
bytesize = "1.0"
cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" }
crates-io = { path = "crates/crates-io", version = "0.31.1" }
-crossbeam-utils = "0.7"
+crossbeam-utils = "0.8"
crypto-hash = "0.3.1"
curl = { version = "0.4.23", features = ["http2"] }
curl-sys = "0.4.22"
-env_logger = "0.7.0"
+env_logger = "0.8.1"
pretty_env_logger = { version = "0.4", optional = true }
anyhow = "1.0"
filetime = "0.2.9"
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
-git2 = "0.13.5"
-git2-curl = "0.14.0"
+git2 = "0.13.14"
+git2-curl = "0.14.1"
glob = "0.3.0"
hex = "0.4"
home = "0.5"
@@ -44,7 +44,7 @@
lazycell = "1.2.0"
libc = "0.2"
log = "0.4.6"
-libgit2-sys = "0.12.7"
+libgit2-sys = "0.12.16"
memchr = "2.1.3"
num_cpus = "1.0"
opener = "0.4"
@@ -59,8 +59,8 @@
strip-ansi-escapes = "0.1.0"
tar = { version = "0.4.26", default-features = false }
tempfile = "3.0"
-termcolor = "1.0"
-toml = "0.5.3"
+termcolor = "1.1"
+toml = "0.5.7"
unicode-xid = "0.2.0"
url = "2.0"
walkdir = "2.2"
@@ -78,8 +78,8 @@
core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }
[target.'cfg(windows)'.dependencies]
-miow = "0.3.1"
-fwdansi = "1"
+miow = "0.3.6"
+fwdansi = "1.1.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
@@ -103,8 +103,12 @@
]
[dev-dependencies]
-cargo-test-macro = { path = "crates/cargo-test-macro", version = "0.1.0" }
-cargo-test-support = { path = "crates/cargo-test-support", version = "0.1.0" }
+cargo-test-macro = { path = "crates/cargo-test-macro" }
+cargo-test-support = { path = "crates/cargo-test-support" }
+
+[build-dependencies]
+flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
+tar = { version = "0.4.26", default-features = false }
[[bin]]
name = "cargo"
diff -Nru cargo-0.47.0/CHANGELOG.md cargo-0.51.0/CHANGELOG.md
--- cargo-0.47.0/CHANGELOG.md 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/CHANGELOG.md 2021-02-04 15:18:32.000000000 +0000
@@ -1,9 +1,269 @@
# Changelog
+## Cargo 1.50 (2021-02-11)
+[8662ab42...HEAD](https://github.com/rust-lang/cargo/compare/8662ab42...HEAD)
+
+### Added
+- Added the `doc` field to `cargo metadata`, which indicates if a target is
+ documented.
+ [#8869](https://github.com/rust-lang/cargo/pull/8869)
+
+### Changed
+- `.crate` files uploaded to a registry are now built with reproducible
+ settings, so that the same `.crate` file created on different machines
+ should be identical.
+ [#8864](https://github.com/rust-lang/cargo/pull/8864)
+
+### Fixed
+
+### Nightly only
+- Allow `resolver="1"` to specify the original feature resolution behavior.
+ [#8857](https://github.com/rust-lang/cargo/pull/8857)
+- Added `-Z extra-link-arg` which adds the `cargo:rustc-link-arg-bins`
+ and `cargo:rustc-link-arg` build script options.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#extra-link-arg)
+ [#8441](https://github.com/rust-lang/cargo/pull/8441)
+
+## Cargo 1.49 (2020-12-31)
+[75615f8e...rust-1.49.0](https://github.com/rust-lang/cargo/compare/75615f8e...rust-1.49.0)
+
+### Added
+- Added `homepage` and `documentation` fields to `cargo metadata`.
+ [#8744](https://github.com/rust-lang/cargo/pull/8744)
+- Added the `CARGO_PRIMARY_PACKAGE` environment variable which is set when
+ running `rustc` if the package is one of the "root" packages selected on the
+ command line.
+ [#8758](https://github.com/rust-lang/cargo/pull/8758)
+- Added support for Unix-style glob patterns for package and target selection
+ flags on the command-line (such as `-p 'serde*'` or `--test '*'`).
+ [#8752](https://github.com/rust-lang/cargo/pull/8752)
+
+### Changed
+- Computed LTO flags are now included in the filename metadata hash so that
+ changes in LTO settings will independently cache build artifacts instead of
+ overwriting previous ones. This prevents rebuilds in some situations such as
+ switching between `cargo build` and `cargo test` in some circumstances.
+ [#8755](https://github.com/rust-lang/cargo/pull/8755)
+- `cargo tree` now displays `(proc-macro)` next to proc-macro packages.
+ [#8765](https://github.com/rust-lang/cargo/pull/8765)
+- Added a warning that the allowed characters for a feature name have been
+ restricted to letters, digits, `_`, `-`, and `+` to accommodate future
+ syntax changes. This is still a superset of the allowed syntax on crates.io,
+ which requires ASCII. This is intended to be changed to an error in the
+ future.
+ [#8814](https://github.com/rust-lang/cargo/pull/8814)
+- `-p` without a value will now print a list of workspace package names.
+ [#8808](https://github.com/rust-lang/cargo/pull/8808)
+
+### Fixed
+- Fixed building a library with both "dylib" and "rlib" crate types with LTO enabled.
+ [#8754](https://github.com/rust-lang/cargo/pull/8754)
+- Fixed paths in Cargo's dep-info files.
+ [#8819](https://github.com/rust-lang/cargo/pull/8819)
+- Fixed inconsistent source IDs in `cargo metadata` for git dependencies that
+ explicitly specify `branch="master"`.
+ [#8824](https://github.com/rust-lang/cargo/pull/8824)
+- Fixed re-extracting dependencies which contained a `.cargo-ok` file.
+ [#8835](https://github.com/rust-lang/cargo/pull/8835)
+
+### Nightly only
+- Fixed a panic with `cargo doc -Zfeatures=itarget` in some situations.
+ [#8777](https://github.com/rust-lang/cargo/pull/8777)
+- New implementation for namespaced features, using the syntax `dep:serde`.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#namespaced-features)
+ [#8799](https://github.com/rust-lang/cargo/pull/8799)
+- Added support for "weak" dependency features, using the syntax
+ `dep_name?/feat_name`, which will enable a feature for a dependency without
+ also enabling the dependency.
+ [#8818](https://github.com/rust-lang/cargo/pull/8818)
+- Fixed the new feature resolver downloading extra dependencies that weren't
+ strictly necessary.
+ [#8823](https://github.com/rust-lang/cargo/pull/8823)
+- Vendored builds now work with `-Zbuild-std`.
+ [#8834](https://github.com/rust-lang/cargo/pull/8834)
+
+## Cargo 1.48 (2020-11-19)
+[51b66125...rust-1.48.0](https://github.com/rust-lang/cargo/compare/51b66125...rust-1.48.0)
+
+### Added
+- Added `term.progress` configuration option to control when and how the
+ progress bar is displayed.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/config.html#termprogresswhen)
+ [#8165](https://github.com/rust-lang/cargo/pull/8165)
+- Added `--message-format plain` option to `cargo locate-project` to display
+ the project location without JSON to make it easier to use in a script.
+ [#8707](https://github.com/rust-lang/cargo/pull/8707)
+- Added `--workspace` option to `cargo locate-project` to display the path to
+ the workspace manifest.
+ [#8712](https://github.com/rust-lang/cargo/pull/8712)
+- A new contributor guide has been added for contributing to Cargo itself.
+ This is published at .
+ [#8715](https://github.com/rust-lang/cargo/pull/8715)
+- Zsh `--target` completion will now complete with the built-in rustc targets.
+ [#8740](https://github.com/rust-lang/cargo/pull/8740)
+
+### Changed
+
+### Fixed
+- Fixed `cargo new` creating a fossil repository to properly ignore the `target` directory.
+ [#8671](https://github.com/rust-lang/cargo/pull/8671)
+- Don't show warnings about the workspace in the current directory when using `cargo install`
+ of a remote package.
+ [#8681](https://github.com/rust-lang/cargo/pull/8681)
+- Automatically reinitialize the index when an "Object not found" error is
+ encountered in the git repository.
+ [#8735](https://github.com/rust-lang/cargo/pull/8735)
+- Updated libgit2, which brings in several fixes for git repository handling.
+ [#8778](https://github.com/rust-lang/cargo/pull/8778)
+ [#8780](https://github.com/rust-lang/cargo/pull/8780)
+
+### Nightly only
+- Fixed `cargo install` so that it will ignore the `[unstable]` table in local config files.
+ [#8656](https://github.com/rust-lang/cargo/pull/8656)
+- Fixed nondeterministic behavior of the new feature resolver.
+ [#8701](https://github.com/rust-lang/cargo/pull/8701)
+- Fixed running `cargo test` on a proc-macro with the new feature resolver
+ under a specific combination of circumstances.
+ [#8742](https://github.com/rust-lang/cargo/pull/8742)
+
+## Cargo 1.47 (2020-10-08)
+[4f74d9b2...rust-1.47.0](https://github.com/rust-lang/cargo/compare/4f74d9b2...rust-1.47.0)
+
+### Added
+- `cargo doc` will now include the package's version in the left sidebar.
+ [#8509](https://github.com/rust-lang/cargo/pull/8509)
+- Added the `test` field to `cargo metadata` targets.
+ [#8478](https://github.com/rust-lang/cargo/pull/8478)
+- Cargo's man pages are now displayed via the `cargo help` command (such as
+ `cargo help build`).
+ [#8456](https://github.com/rust-lang/cargo/pull/8456)
+ [#8577](https://github.com/rust-lang/cargo/pull/8577)
+- Added new documentation chapters on [how dependency resolution
+ works](https://doc.rust-lang.org/nightly/cargo/reference/resolver.html) and
+ [SemVer
+ compatibility](https://doc.rust-lang.org/nightly/cargo/reference/semver.html),
+ along with suggestions on how to version your project and work with
+ dependencies.
+ [#8609](https://github.com/rust-lang/cargo/pull/8609)
+
+### Changed
+- The comments added to `.gitignore` when it is modified have been tweaked to
+ add some spacing.
+ [#8476](https://github.com/rust-lang/cargo/pull/8476)
+- `cargo metadata` output should now be sorted to be deterministic.
+ [#8489](https://github.com/rust-lang/cargo/pull/8489)
+- By default, build scripts and proc-macros are now built with `opt-level=0`
+ and the default codegen units, even in release mode.
+ [#8500](https://github.com/rust-lang/cargo/pull/8500)
+- `workspace.default-members` is now filtered by `workspace.exclude`.
+ [#8485](https://github.com/rust-lang/cargo/pull/8485)
+- `workspace.members` globs now ignore non-directory paths.
+ [#8511](https://github.com/rust-lang/cargo/pull/8511)
+- git zlib errors now trigger a retry.
+ [#8520](https://github.com/rust-lang/cargo/pull/8520)
+- "http" class git errors now trigger a retry.
+ [#8553](https://github.com/rust-lang/cargo/pull/8553)
+- git dependencies now override the `core.autocrlf` git configuration value to
+ ensure they behave consistently across platforms, particularly when
+ vendoring git dependencies on Windows.
+ [#8523](https://github.com/rust-lang/cargo/pull/8523)
+- If `Cargo.lock` needs to be updated, then it will be automatically
+ transitioned to the new V2 format. This format removes the `[metadata]`
+ table, and should be easier to merge changes in source control systems. This
+ format was introduced in 1.38, and made the default for new projects in
+ 1.41.
+ [#8554](https://github.com/rust-lang/cargo/pull/8554)
+- Added preparation for support of git repositories with a non-"master"
+ default branch. Actual support will arrive in a future version. This
+ introduces some warnings:
+ - Warn if a git dependency does not specify a branch, and the default branch
+ on the repository is not "master". In the future, Cargo will fetch the
+ default branch. In this scenario, the branch should be explicitly
+ specified.
+ - Warn if a workspace has multiple dependencies to the same git repository,
+ one without a `branch` and one with `branch="master"`. Dependencies should
+ all use one form or the other.
+ [#8522](https://github.com/rust-lang/cargo/pull/8522)
+- Warnings are now issued if a `required-features` entry lists a feature that
+ does not exist.
+ [#7950](https://github.com/rust-lang/cargo/pull/7950)
+- Built-in aliases are now included in `cargo --list`.
+ [#8542](https://github.com/rust-lang/cargo/pull/8542)
+- `cargo install` with a specific version that has been yanked will now
+ display an error message that it has been yanked, instead of "could not
+ find".
+ [#8565](https://github.com/rust-lang/cargo/pull/8565)
+- `cargo publish` with a package that has the `publish` field set to a single
+ registry, and no `--registry` flag has been given, will now publish to that
+ registry instead of generating an error.
+ [#8571](https://github.com/rust-lang/cargo/pull/8571)
+
+### Fixed
+- Fixed issue where if a project directory was moved, and one of the
+ build scripts did not use the `rerun-if-changed` directive, then that
+ build script was being rebuilt when it shouldn't.
+ [#8497](https://github.com/rust-lang/cargo/pull/8497)
+- Console colors should now work on Windows 7 and 8.
+ [#8540](https://github.com/rust-lang/cargo/pull/8540)
+- The `CARGO_TARGET_{triplet}_RUNNER` environment variable will now correctly
+ override the config file instead of trying to merge the commands.
+ [#8629](https://github.com/rust-lang/cargo/pull/8629)
+- Fixed LTO with doctests.
+ [#8657](https://github.com/rust-lang/cargo/pull/8657)
+ [#8658](https://github.com/rust-lang/cargo/pull/8658)
+
+### Nightly only
+- Added support for `-Z terminal-width` which tells `rustc` the width of the
+ terminal so that it can format diagnostics better.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#terminal-width)
+ [#8427](https://github.com/rust-lang/cargo/pull/8427)
+- Added ability to configure `-Z` unstable flags in config files via the
+ `[unstable]` table.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html)
+ [#8393](https://github.com/rust-lang/cargo/pull/8393)
+- Added `-Z build-std-features` flag to set features for the standard library.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std-features)
+ [#8490](https://github.com/rust-lang/cargo/pull/8490)
+
## Cargo 1.46 (2020-08-27)
-[9fcb8c1d...HEAD](https://github.com/rust-lang/cargo/compare/9fcb8c1d...HEAD)
+[9fcb8c1d...rust-1.46.0](https://github.com/rust-lang/cargo/compare/9fcb8c1d...rust-1.46.0)
### Added
+- The `dl` key in `config.json` of a registry index now supports the
+ replacement markers `{prefix}` and `{lowerprefix}` to allow spreading crates
+ across directories similar to how the index itself is structured.
+ [docs](https://doc.rust-lang.org/nightly/cargo/reference/registries.html#index-format)
+ [#8267](https://github.com/rust-lang/cargo/pull/8267)
+- Added new environment variables that are set during compilation:
+ - `CARGO_CRATE_NAME`: The name of the crate being built.
+ - `CARGO_BIN_NAME`: The name of the executable binary (if this is a binary crate).
+ - `CARGO_PKG_LICENSE`: The `license` field from the manifest.
+ - `CARGO_PKG_LICENSE_FILE`: The `license-file` field from the manifest.
+ [#8270](https://github.com/rust-lang/cargo/pull/8270)
+ [#8325](https://github.com/rust-lang/cargo/pull/8325)
+ [#8387](https://github.com/rust-lang/cargo/pull/8387)
+- If the value for `readme` is not specified in `Cargo.toml`, it is now
+ automatically inferred from the existence of a file named `README`,
+ `README.md`, or `README.txt`. This can be suppressed by setting
+ `readme = false`.
+ [#8277](https://github.com/rust-lang/cargo/pull/8277)
+- `cargo install` now supports the `--index` flag to install directly from an index.
+ [#8344](https://github.com/rust-lang/cargo/pull/8344)
+- Added the `metadata` table to the `workspace` definition in `Cargo.toml`.
+ This can be used for arbitrary data similar to the `package.metadata` table.
+ [#8323](https://github.com/rust-lang/cargo/pull/8323)
+- Added the `--target-dir` flag to `cargo install` to set the target directory.
+ [#8391](https://github.com/rust-lang/cargo/pull/8391)
+- Changes to environment variables used by the
+ [`env!`](https://doc.rust-lang.org/std/macro.env.html) or
+ [`option_env!`](https://doc.rust-lang.org/std/macro.option_env.html) macros
+ are now automatically detected to trigger a rebuild.
+ [#8421](https://github.com/rust-lang/cargo/pull/8421)
+- The `target` directory now includes the `CACHEDIR.TAG` file which is used by
+ some tools to exclude the directory from backups.
+ [#8378](https://github.com/rust-lang/cargo/pull/8378)
+- Added docs about rustup's `+toolchain` syntax.
+ [#8455](https://github.com/rust-lang/cargo/pull/8455)
### Changed
- A warning is now displayed if a git dependency includes a `#` fragment in
@@ -11,6 +271,17 @@
URLs with this syntax, but it does not have any meaning outside of the
`Cargo.lock` file, and would not work properly.
[#8297](https://github.com/rust-lang/cargo/pull/8297)
+- Various optimizations and fixes for bitcode embedding and LTO.
+ [#8349](https://github.com/rust-lang/cargo/pull/8349)
+- Reduced the amount of data fetched for git dependencies. If Cargo knows the
+ branch or tag to fetch, it will now only fetch that branch or tag instead of
+ all branches and tags.
+ [#8363](https://github.com/rust-lang/cargo/pull/8363)
+- Enhanced git fetch error messages.
+ [#8409](https://github.com/rust-lang/cargo/pull/8409)
+- `.crate` files are now generated with GNU tar format instead of UStar, which
+ supports longer file names.
+ [#8453](https://github.com/rust-lang/cargo/pull/8453)
### Fixed
- Fixed a rare situation where an update to `Cargo.lock` failed once, but then
@@ -22,6 +293,27 @@
- Updated libgit2, which brings in a fix for zlib errors for some remote
git servers like googlesource.com.
[#8320](https://github.com/rust-lang/cargo/pull/8320)
+- Fixed the GitHub fast-path check for up-to-date git dependencies on
+ non-master branches.
+ [#8363](https://github.com/rust-lang/cargo/pull/8363)
+- Fixed issue when enabling a feature with `pkg/feature` syntax, and `pkg` is
+ an optional dependency, but also a dev-dependency, and the dev-dependency
+ appears before the optional normal dependency in the registry summary, then
+ the optional dependency would not get activated.
+ [#8395](https://github.com/rust-lang/cargo/pull/8395)
+- Fixed `clean -p` deleting the build directory if there is a test named
+ `build`.
+ [#8398](https://github.com/rust-lang/cargo/pull/8398)
+- Fixed indentation of multi-line Cargo error messages.
+ [#8409](https://github.com/rust-lang/cargo/pull/8409)
+- Fixed issue where the automatic inclusion of the `--document-private-items`
+ flag for rustdoc would override any flags passed to the `cargo rustdoc`
+ command.
+ [#8449](https://github.com/rust-lang/cargo/pull/8449)
+- Cargo will now include a version in the hash of the fingerprint directories
+ to support backwards-incompatible changes to the fingerprint structure.
+ [#8473](https://github.com/rust-lang/cargo/pull/8473)
+ [#8488](https://github.com/rust-lang/cargo/pull/8488)
### Nightly only
- Added `-Zrustdoc-map` feature which provides external mappings for rustdoc
@@ -31,7 +323,10 @@
- Fixed feature calculation when a proc-macro is declared in `Cargo.toml` with
an underscore (like `proc_macro = true`).
[#8319](https://github.com/rust-lang/cargo/pull/8319)
-
+- Added support for setting `-Clinker` with `-Zdoctest-xcompile`.
+ [#8359](https://github.com/rust-lang/cargo/pull/8359)
+- Fixed setting the `strip` profile field in config files.
+ [#8454](https://github.com/rust-lang/cargo/pull/8454)
## Cargo 1.45 (2020-07-16)
[ebda5065e...rust-1.45.0](https://github.com/rust-lang/cargo/compare/ebda5065...rust-1.45.0)
diff -Nru cargo-0.47.0/ci/azure-install-rust.yml cargo-0.51.0/ci/azure-install-rust.yml
--- cargo-0.47.0/ci/azure-install-rust.yml 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/ci/azure-install-rust.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,18 +0,0 @@
-steps:
- - bash: |
- set -e
- rustup set profile minimal
- rustup component remove --toolchain=$TOOLCHAIN rust-docs || echo "already removed"
- rustup update --no-self-update $TOOLCHAIN
- if [[ "$TOOLCHAIN" == "nightly"* ]]; then
- rustup component add --toolchain=$TOOLCHAIN rustc-dev llvm-tools-preview rust-docs
- fi
- rustup default $TOOLCHAIN
- displayName: Install rust
-
- - bash: |
- set -ex
- rustup -V
- rustc -Vv
- cargo -V
- displayName: Query rust and cargo versions
diff -Nru cargo-0.47.0/ci/azure-test-all.yml cargo-0.51.0/ci/azure-test-all.yml
--- cargo-0.47.0/ci/azure-test-all.yml 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/ci/azure-test-all.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,33 +0,0 @@
-steps:
-- checkout: self
- fetchDepth: 1
-
-- template: azure-install-rust.yml
-
-- bash: rustup target add $OTHER_TARGET
- displayName: "Install cross-compile target"
-
-- bash: sudo apt update -y && sudo apt install gcc-multilib -y
- displayName: "Install gcc-multilib (linux)"
- condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
-
-# Some tests also rely on rustfmt
-- bash: rustup component add rustfmt || echo "rustfmt not available"
- displayName: "Install rustfmt (maybe)"
-
-# Deny warnings on CI to avoid warnings getting into the codebase, and note the
-# `force-system-lib-on-osx` which is intended to fix compile issues on OSX where
-# compiling curl from source on OSX yields linker errors on Azure.
-#
-# Note that the curl issue is traced back to alexcrichton/curl-rust#279 where it
-# looks like the OSX version we're actually running on is such that a symbol is
-# emitted that's never worked. For now force the system library to be used to
-# fix the link errors.
-- bash: cargo test --features 'deny-warnings curl/force-system-lib-on-osx'
- displayName: "cargo test"
-
-- bash: cargo test -p cargo-test-support
- displayName: "cargo test -p cargo-test-support"
-
-- bash: cargo test -p cargo-platform
- displayName: "cargo test -p cargo-platform"
diff -Nru cargo-0.47.0/ci/validate-man.sh cargo-0.51.0/ci/validate-man.sh
--- cargo-0.47.0/ci/validate-man.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/ci/validate-man.sh 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,26 @@
+#!/bin/bash
+# This script validates that there aren't any changes to the man pages.
+
+set -e
+
+cd src/doc
+
+changes=$(git status --porcelain)
+if [ -n "$changes" ]
+then
+ echo "git directory must be clean before running this script."
+ exit 1
+fi
+
+./build-man.sh
+
+changes=$(git status --porcelain)
+if [ -n "$changes" ]
+then
+ echo "Detected changes in man pages:"
+ echo "$changes"
+ echo
+ echo "Please run './build-man.sh' in the src/doc directory to rebuild the"
+ echo "man pages, and commit the changes."
+ exit 1
+fi
diff -Nru cargo-0.47.0/CONTRIBUTING.md cargo-0.51.0/CONTRIBUTING.md
--- cargo-0.47.0/CONTRIBUTING.md 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/CONTRIBUTING.md 2021-02-04 15:18:32.000000000 +0000
@@ -1,232 +1,5 @@
# Contributing to Cargo
-Thank you for your interest in contributing to Cargo! Good places to
-start are this document, [ARCHITECTURE.md](ARCHITECTURE.md), which
-describes the high-level structure of Cargo and [E-easy] bugs on the
-issue tracker.
+Contributing documentation has moved to the **[Cargo Contributor Guide]**.
-If you have a general question about Cargo or it's internals, feel free to ask
-on [Zulip].
-
-## Code of Conduct
-
-All contributors are expected to follow our [Code of Conduct].
-
-## Bug reports
-
-We can't fix what we don't know about, so please report problems liberally. This
-includes problems with understanding the documentation, unhelpful error messages
-and unexpected behavior.
-
-**If you think that you have identified an issue with Cargo that might compromise
-its users' security, please do not open a public issue on GitHub. Instead,
-we ask you to refer to Rust's [security policy].**
-
-Opening an issue is as easy as following [this link][new-issues] and filling out
-the fields. Here's a template that you can use to file an issue, though it's not
-necessary to use it exactly:
-
-
-
- I tried this:
-
- I expected to see this happen:
-
- Instead, this happened:
-
- I'm using
+
+
man — A troff-style man page. Outputs with a numbered extension (like
+.1) matching the man page section.
+
md — A markdown file, after all handlebars processing has been finished.
+Outputs with the .md extension.
+
txt — A text file, rendered for situations where a man page viewer isn't
+available. Outputs with the .txt extension.
+
+
+
+
-ooutdir
+
Specifies the directory where to save the output.
+
+
+
--urlbase_url
+
Specifies a base URL to use for relative URLs within the document. Any
+relative URL will be joined with this URL.
+
+
+
--manname:section=url
+
Specifies a URL to use for the given man page. When the {{man name section}} expression is used, the given URL will be inserted as a link. This
+may be specified multiple times. If a man page reference does not have a
+matching --man entry, then a relative link to a file named name.md will
+be used.
+
+
+
sources...
+
The source input filename, may be specified multiple times.
+
+
+
+
+## EXAMPLES
+
+1. Convert the given documents to man pages:
+
+ mdman -t man -o doc doc/mdman.md
diff -Nru cargo-0.47.0/crates/mdman/doc/out/mdman.txt cargo-0.51.0/crates/mdman/doc/out/mdman.txt
--- cargo-0.47.0/crates/mdman/doc/out/mdman.txt 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/doc/out/mdman.txt 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,91 @@
+MDMAN(1)
+
+NAME
+ mdman - Converts markdown to a man page
+
+SYNOPSIS
+ mdman [options] -t type -o outdir sources...
+
+DESCRIPTION
+ Converts a markdown file to a man page.
+
+ The source file is first processed as a handlebars
+ template. Then, it is processed as markdown
+ into the target format. This supports different output formats, such as
+ troff or plain text.
+
+ Every man page should start with a level-1 header with the man name and
+ section, such as # mdman(1).
+
+ The handlebars template has several special tags to assist with
+ generating the man page:
+
+ o Every block of command-line options must be wrapped between
+ {{#options}} and {{/options}} tags. This tells the processor where
+ the options start and end.
+
+ o Each option must be expressed with a {{#option}} block. The
+ parameters to the the block are a sequence of strings indicating the
+ option. For example, {{#option "`-p` _spec_..." "`--package`
+ _spec_..."}} is an option that has two different forms. The text
+ within the string is processed as markdown. It is recommended to use
+ formatting similar to this example.
+
+ The content of the {{#option}} block should contain a detailed
+ description of the option.
+
+ Use the {{/option}} tag to end the option block.
+
+ o References to other man pages should use the {{man name section}}
+ expression. For example, {{man "mdman" 1}} will generate a reference
+ to the mdman(1) man page. For non-troff output, the --man option will
+ tell mdman how to create links to the man page. If there is no
+ matching --man option, then it links to a file named name.md in the
+ same directory.
+
+ o Variables can be set with {{*set name="value"}}. These variables can
+ then be referenced with {{name}} expressions.
+
+ o Partial templates should be placed in a directory named includes next
+ to the source file. Templates can be included with an expression like
+ {{> template-name}}.
+
+ o Other helpers include:
+
+ o {{lower value}} Converts the given value to lowercase.
+
+OPTIONS
+ -t type
+ Specifies the output type. The following output types are supported:
+
+ o man — A troff-style man page. Outputs with a numbered
+ extension (like .1) matching the man page section.
+
+ o md — A markdown file, after all handlebars processing has been
+ finished. Outputs with the .md extension.
+
+ o txt — A text file, rendered for situations where a man page
+ viewer isn't available. Outputs with the .txt extension.
+
+ -o outdir
+ Specifies the directory where to save the output.
+
+ --url base_url
+ Specifies a base URL to use for relative URLs within the document.
+ Any relative URL will be joined with this URL.
+
+ --man name:section=url
+ Specifies a URL to use for the given man page. When the {{man name
+ section}} expression is used, the given URL will be inserted as a
+ link. This may be specified multiple times. If a man page reference
+ does not have a matching --man entry, then a relative link to a file
+ named name.md will be used.
+
+ sources...
+ The source input filename, may be specified multiple times.
+
+EXAMPLES
+ 1. Convert the given documents to man pages:
+
+ mdman -t man -o doc doc/mdman.md
+
diff -Nru cargo-0.47.0/crates/mdman/README.md cargo-0.51.0/crates/mdman/README.md
--- cargo-0.47.0/crates/mdman/README.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/README.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,7 @@
+# mdman
+
+mdman is a small utility for creating man pages from markdown text files.
+
+## Usage
+
+See the [man page](doc/out/mdman.md) generated by this tool.
diff -Nru cargo-0.47.0/crates/mdman/src/format/man.rs cargo-0.51.0/crates/mdman/src/format/man.rs
--- cargo-0.47.0/crates/mdman/src/format/man.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/src/format/man.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,430 @@
+//! Man-page formatter.
+
+use crate::util::{header_text, parse_name_and_section};
+use crate::EventIter;
+use anyhow::{bail, Error};
+use pulldown_cmark::{Alignment, Event, LinkType, Tag};
+use std::fmt::Write;
+use url::Url;
+
+pub struct ManFormatter {
+ url: Option,
+}
+
+impl ManFormatter {
+ pub fn new(url: Option) -> ManFormatter {
+ ManFormatter { url }
+ }
+}
+
+impl super::Formatter for ManFormatter {
+ fn render(&self, input: &str) -> Result {
+ ManRenderer::render(input, self.url.clone())
+ }
+
+ fn render_options_start(&self) -> &'static str {
+ // Tell pulldown_cmark to ignore this.
+ // This will be stripped out later.
+ " &'static str {
+ "]]>"
+ }
+
+ fn render_option(
+ &self,
+ params: &[&str],
+ block: &str,
+ _man_name: &str,
+ ) -> Result {
+ let rendered_options = params
+ .iter()
+ .map(|param| {
+ let r = self.render(param)?;
+ Ok(r.trim().trim_start_matches(".sp").to_string())
+ })
+ .collect::, Error>>()?;
+ let rendered_block = self.render(block)?;
+ let rendered_block = rendered_block.trim().trim_start_matches(".sp").trim();
+ // .RS = move left margin to right 4.
+ // .RE = move margin back one level.
+ Ok(format!(
+ "\n.sp\n{}\n.RS 4\n{}\n.RE\n",
+ rendered_options.join(", "),
+ rendered_block
+ ))
+ }
+
+ fn linkify_man_to_md(&self, name: &str, section: u8) -> Result {
+ Ok(format!("`{}`({})", name, section))
+ }
+}
+
+#[derive(Copy, Clone)]
+enum Font {
+ Bold,
+ Italic,
+}
+
+impl Font {
+ fn str_from_stack(font_stack: &[Font]) -> &'static str {
+ let has_bold = font_stack.iter().any(|font| matches!(font, Font::Bold));
+ let has_italic = font_stack.iter().any(|font| matches!(font, Font::Italic));
+ match (has_bold, has_italic) {
+ (false, false) => "\\fR", // roman (normal)
+ (false, true) => "\\fI", // italic
+ (true, false) => "\\fB", // bold
+ (true, true) => "\\f(BI", // bold italic
+ }
+ }
+}
+
+struct ManRenderer<'e> {
+ output: String,
+ parser: EventIter<'e>,
+ font_stack: Vec,
+}
+
+impl<'e> ManRenderer<'e> {
+ fn render(input: &str, url: Option) -> Result {
+ let parser = crate::md_parser(input, url);
+ let output = String::with_capacity(input.len() * 3 / 2);
+ let mut mr = ManRenderer {
+ parser,
+ output,
+ font_stack: Vec::new(),
+ };
+ mr.push_man()?;
+ Ok(mr.output)
+ }
+
+ fn push_man(&mut self) -> Result<(), Error> {
+ // If this is true, this is inside a cdata block used for hiding
+ // content from pulldown_cmark.
+ let mut in_cdata = false;
+ // The current list stack. None if unordered, Some if ordered with the
+ // given number as the current index.
+ let mut list: Vec
> = Vec::new();
+ // Used in some cases where spacing isn't desired.
+ let mut suppress_paragraph = false;
+ let mut table_cell_index = 0;
+
+ while let Some((event, range)) = self.parser.next() {
+ let this_suppress_paragraph = suppress_paragraph;
+ suppress_paragraph = false;
+ match event {
+ Event::Start(tag) => {
+ match tag {
+ Tag::Paragraph => {
+ if !this_suppress_paragraph {
+ self.flush();
+ self.output.push_str(".sp\n");
+ }
+ }
+ Tag::Heading(n) => {
+ if n == 1 {
+ self.push_top_header()?;
+ } else if n == 2 {
+ // Section header
+ let text = header_text(&mut self.parser)?;
+ self.flush();
+ write!(self.output, ".SH \"{}\"\n", text)?;
+ suppress_paragraph = true;
+ } else {
+ // Subsection header
+ let text = header_text(&mut self.parser)?;
+ self.flush();
+ write!(self.output, ".SS \"{}\"\n", text)?;
+ suppress_paragraph = true;
+ }
+ }
+ Tag::BlockQuote => {
+ self.flush();
+ // .RS = move left margin over 3
+ // .ll = shrink line length
+ self.output.push_str(".RS 3\n.ll -5\n.sp\n");
+ suppress_paragraph = true;
+ }
+ Tag::CodeBlock(_kind) => {
+ // space down, indent 4, no-fill mode
+ self.flush();
+ self.output.push_str(".sp\n.RS 4\n.nf\n");
+ }
+ Tag::List(start) => list.push(start),
+ Tag::Item => {
+ // Note: This uses explicit movement instead of .IP
+ // because the spacing on .IP looks weird to me.
+ // space down, indent 4
+ self.flush();
+ self.output.push_str(".sp\n.RS 4\n");
+ match list.last_mut().expect("item must have list start") {
+ // Ordered list.
+ Some(n) => {
+ // move left 4, output the list index number, move right 1.
+ write!(self.output, "\\h'-04' {}.\\h'+01'", n)?;
+ *n += 1;
+ }
+ // Unordered list.
+ None => self.output.push_str("\\h'-04'\\(bu\\h'+02'"),
+ }
+ suppress_paragraph = true;
+ }
+ Tag::FootnoteDefinition(_label) => unimplemented!(),
+ Tag::Table(alignment) => {
+ // Table start
+ // allbox = draw a box around all the cells
+ // tab(:) = Use `:` to separate cell data (instead of tab)
+ // ; = end of options
+ self.output.push_str(
+ "\n.TS\n\
+ allbox tab(:);\n",
+ );
+ let alignments: Vec<_> = alignment
+ .iter()
+ .map(|a| match a {
+ Alignment::Left | Alignment::None => "lt",
+ Alignment::Center => "ct",
+ Alignment::Right => "rt",
+ })
+ .collect();
+ self.output.push_str(&alignments.join(" "));
+ self.output.push_str(".\n");
+ table_cell_index = 0;
+ }
+ Tag::TableHead => {
+ table_cell_index = 0;
+ }
+ Tag::TableRow => {
+ table_cell_index = 0;
+ self.output.push('\n');
+ }
+ Tag::TableCell => {
+ if table_cell_index != 0 {
+ // Separator between columns.
+ self.output.push(':');
+ }
+ // Start a text block.
+ self.output.push_str("T{\n");
+ table_cell_index += 1
+ }
+ Tag::Emphasis => self.push_font(Font::Italic),
+ Tag::Strong => self.push_font(Font::Bold),
+ // Strikethrough isn't usually supported for TTY.
+ Tag::Strikethrough => self.output.push_str("~~"),
+ Tag::Link(link_type, dest_url, _title) => {
+ if dest_url.starts_with('#') {
+ // In a man page, page-relative anchors don't
+ // have much meaning.
+ continue;
+ }
+ match link_type {
+ LinkType::Autolink | LinkType::Email => {
+ // The text is a copy of the URL, which is not needed.
+ match self.parser.next() {
+ Some((Event::Text(_), _range)) => {}
+ _ => bail!("expected text after autolink"),
+ }
+ }
+ LinkType::Inline
+ | LinkType::Reference
+ | LinkType::Collapsed
+ | LinkType::Shortcut => {
+ self.push_font(Font::Italic);
+ }
+ // This is currently unused. This is only
+ // emitted with a broken link callback, but I
+ // felt it is too annoying to escape `[` in
+ // option descriptions.
+ LinkType::ReferenceUnknown
+ | LinkType::CollapsedUnknown
+ | LinkType::ShortcutUnknown => {
+ bail!(
+ "link with missing reference `{}` located at offset {}",
+ dest_url,
+ range.start
+ );
+ }
+ }
+ }
+ Tag::Image(_link_type, _dest_url, _title) => {
+ bail!("images are not currently supported")
+ }
+ }
+ }
+ Event::End(tag) => {
+ match &tag {
+ Tag::Paragraph => self.flush(),
+ Tag::Heading(_n) => {}
+ Tag::BlockQuote => {
+ self.flush();
+ // restore left margin, restore line length
+ self.output.push_str(".br\n.RE\n.ll\n");
+ }
+ Tag::CodeBlock(_kind) => {
+ self.flush();
+ // Restore fill mode, move margin back one level.
+ self.output.push_str(".fi\n.RE\n");
+ }
+ Tag::List(_) => {
+ list.pop();
+ }
+ Tag::Item => {
+ self.flush();
+ // Move margin back one level.
+ self.output.push_str(".RE\n");
+ }
+ Tag::FootnoteDefinition(_label) => {}
+ Tag::Table(_) => {
+ // Table end
+ // I don't know why, but the .sp is needed to provide
+ // space with the following content.
+ self.output.push_str("\n.TE\n.sp\n");
+ }
+ Tag::TableHead => {}
+ Tag::TableRow => {}
+ Tag::TableCell => {
+ // End text block.
+ self.output.push_str("\nT}");
+ }
+ Tag::Emphasis | Tag::Strong => self.pop_font(),
+ Tag::Strikethrough => self.output.push_str("~~"),
+ Tag::Link(link_type, dest_url, _title) => {
+ if dest_url.starts_with('#') {
+ continue;
+ }
+ match link_type {
+ LinkType::Autolink | LinkType::Email => {}
+ LinkType::Inline
+ | LinkType::Reference
+ | LinkType::Collapsed
+ | LinkType::Shortcut => {
+ self.pop_font();
+ self.output.push(' ');
+ }
+ _ => {
+ panic!("unexpected tag {:?}", tag);
+ }
+ }
+ write!(self.output, "<{}>", escape(&dest_url)?)?;
+ }
+ Tag::Image(_link_type, _dest_url, _title) => {}
+ }
+ }
+ Event::Text(t) => {
+ self.output.push_str(&escape(&t)?);
+ }
+ Event::Code(t) => {
+ self.push_font(Font::Bold);
+ self.output.push_str(&escape(&t)?);
+ self.pop_font();
+ }
+ Event::Html(t) => {
+ if t.starts_with("") {
+ in_cdata = false;
+ } else if !t.trim().is_empty() {
+ self.output.push_str(&t);
+ }
+ } else {
+ self.output.push_str(&escape(&t)?);
+ }
+ }
+ Event::FootnoteReference(_t) => {}
+ Event::SoftBreak => self.output.push('\n'),
+ Event::HardBreak => {
+ self.flush();
+ self.output.push_str(".br\n");
+ }
+ Event::Rule => {
+ self.flush();
+ // \l' **length** ' Draw horizontal line (default underscore).
+ // \n(.lu Gets value from register "lu" (current line length)
+ self.output.push_str("\\l'\\n(.lu'\n");
+ }
+ Event::TaskListMarker(_b) => unimplemented!(),
+ }
+ }
+ Ok(())
+ }
+
+ fn flush(&mut self) {
+ if !self.output.ends_with('\n') {
+ self.output.push('\n');
+ }
+ }
+
+ /// Switch to the given font.
+ ///
+ /// Because the troff sequence `\fP` for switching to the "previous" font
+ /// doesn't support nesting, this needs to emulate it here. This is needed
+ /// for situations like **hi _there_**.
+ fn push_font(&mut self, font: Font) {
+ self.font_stack.push(font);
+ self.output.push_str(Font::str_from_stack(&self.font_stack));
+ }
+
+ fn pop_font(&mut self) {
+ self.font_stack.pop();
+ self.output.push_str(Font::str_from_stack(&self.font_stack));
+ }
+
+ /// Parse and render the first top-level header of the document.
+ fn push_top_header(&mut self) -> Result<(), Error> {
+ // This enables the tbl preprocessor for tables.
+ // This seems to be enabled by default on every modern system I could
+ // find, but it doesn't seem to hurt to enable this.
+ self.output.push_str("'\\\" t\n");
+ // Extract the name of the man page.
+ let text = header_text(&mut self.parser)?;
+ let (name, section) = parse_name_and_section(&text)?;
+ // .TH = Table header
+ // .nh = disable hyphenation
+ // .ad l = Left-adjust mode (disable justified).
+ // .ss sets sentence_space_size to 0 (prevents double spaces after .
+ // if . is last on the line)
+ write!(
+ self.output,
+ ".TH \"{}\" \"{}\"\n\
+ .nh\n\
+ .ad l\n\
+ .ss \\n[.ss] 0\n",
+ escape(&name.to_uppercase())?,
+ section
+ )?;
+ Ok(())
+ }
+}
+
+fn escape(s: &str) -> Result {
+ let mut replaced = s
+ .replace('\\', "\\(rs")
+ .replace('-', "\\-")
+ .replace('\u{00A0}', "\\ ") // non-breaking space (non-stretchable)
+ .replace('–', "\\[en]") // \u{2013} en-dash
+ .replace('—', "\\[em]") // \u{2014} em-dash
+ .replace('│', "|") // \u{2502} box drawing light vertical (could use \[br])
+ .replace('├', "|") // \u{251C} box drawings light vertical and right
+ .replace('└', "`") // \u{2514} box drawings light up and right
+ .replace('─', "\\-") // \u{2500} box drawing light horizontal
+ ;
+ if replaced.starts_with('.') {
+ replaced = format!("\\&.{}", &replaced[1..]);
+ } else if replaced.starts_with('\'') {
+ replaced = format!("\\(aq{}", &replaced[1..]);
+ }
+
+ if let Some(ch) = replaced.chars().find(|ch| {
+ !matches!(ch, '\n' | ' ' | '!'..='/' | '0'..='9'
+ | ':'..='@' | 'A'..='Z' | '['..='`' | 'a'..='z' | '{'..='~')
+ }) {
+ bail!(
+ "character {:?} is not allowed (update the translation table if needed)",
+ ch
+ );
+ }
+ Ok(replaced)
+}
diff -Nru cargo-0.47.0/crates/mdman/src/format/md.rs cargo-0.51.0/crates/mdman/src/format/md.rs
--- cargo-0.47.0/crates/mdman/src/format/md.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/src/format/md.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,112 @@
+//! Markdown formatter.
+
+use crate::util::unwrap;
+use crate::ManMap;
+use anyhow::{bail, format_err, Error};
+use std::fmt::Write;
+
+pub struct MdFormatter {
+ man_map: ManMap,
+}
+
+impl MdFormatter {
+ pub fn new(man_map: ManMap) -> MdFormatter {
+ MdFormatter { man_map }
+ }
+}
+
+impl MdFormatter {
+ fn render_html(&self, input: &str) -> Result {
+ let parser = crate::md_parser(input, None);
+ let mut html_output: String = String::with_capacity(input.len() * 3 / 2);
+ pulldown_cmark::html::push_html(&mut html_output, parser.map(|(e, _r)| e));
+ Ok(html_output)
+ }
+}
+
+impl super::Formatter for MdFormatter {
+ fn render(&self, input: &str) -> Result {
+ Ok(input.replace("\r\n", "\n"))
+ }
+
+ fn render_options_start(&self) -> &'static str {
+ "
")
+ }
+
+ for param in params {
+ let rendered = self.render_html(param)?;
+ let no_p = unwrap_p(&rendered);
+ // split out first term to use as the id.
+ let first = no_p
+ .split_whitespace()
+ .next()
+ .ok_or_else(|| format_err!("did not expect option `{}` to be empty", param))?;
+ let no_tags = trim_tags(first);
+ if no_tags.is_empty() {
+ bail!("unexpected empty option with no tags `{}`", param);
+ }
+ let id = format!("option-{}-{}", man_name, no_tags);
+ write!(
+ result,
+ "
\n",
+ unwrap_p(&rendered_block)
+ )?;
+ Ok(result)
+ }
+
+ fn linkify_man_to_md(&self, name: &str, section: u8) -> Result {
+ let s = match self.man_map.get(&(name.to_string(), section)) {
+ Some(link) => format!("[{}({})]({})", name, section, link),
+ None => format!("[{}({})]({}.html)", name, section, name),
+ };
+ Ok(s)
+ }
+}
+
+fn trim_tags(s: &str) -> String {
+ // This is a hack. It removes all HTML tags.
+ let mut in_tag = false;
+ let mut in_char_ref = false;
+ s.chars()
+ .filter(|&ch| match ch {
+ '<' if in_tag => panic!("unexpected nested tag"),
+ '&' if in_char_ref => panic!("unexpected nested char ref"),
+ '<' => {
+ in_tag = true;
+ false
+ }
+ '&' => {
+ in_char_ref = true;
+ false
+ }
+ '>' if in_tag => {
+ in_tag = false;
+ false
+ }
+ ';' if in_char_ref => {
+ in_char_ref = false;
+ false
+ }
+ _ => !in_tag && !in_char_ref,
+ })
+ .collect()
+}
diff -Nru cargo-0.47.0/crates/mdman/src/format/text.rs cargo-0.51.0/crates/mdman/src/format/text.rs
--- cargo-0.47.0/crates/mdman/src/format/text.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/src/format/text.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,605 @@
+//! Text formatter.
+
+use crate::util::{header_text, unwrap};
+use crate::EventIter;
+use anyhow::{bail, Error};
+use pulldown_cmark::{Alignment, Event, LinkType, Tag};
+use std::fmt::Write;
+use std::mem;
+use url::Url;
+
+pub struct TextFormatter {
+ url: Option,
+}
+
+impl TextFormatter {
+ pub fn new(url: Option) -> TextFormatter {
+ TextFormatter { url }
+ }
+}
+
+impl super::Formatter for TextFormatter {
+ fn render(&self, input: &str) -> Result {
+ TextRenderer::render(input, self.url.clone(), 0)
+ }
+
+ fn render_options_start(&self) -> &'static str {
+ // Tell pulldown_cmark to ignore this.
+ // This will be stripped out later.
+ " &'static str {
+ "]]>"
+ }
+
+ fn render_option(
+ &self,
+ params: &[&str],
+ block: &str,
+ _man_name: &str,
+ ) -> Result {
+ let rendered_options = params
+ .iter()
+ .map(|param| TextRenderer::render(param, self.url.clone(), 0))
+ .collect::, Error>>()?;
+ let trimmed: Vec<_> = rendered_options.iter().map(|o| o.trim()).collect();
+ // Wrap in HTML tags, they will be stripped out during rendering.
+ Ok(format!(
+ "
{}
\n
{}
\n \n",
+ trimmed.join(", "),
+ block
+ ))
+ }
+
+ fn linkify_man_to_md(&self, name: &str, section: u8) -> Result {
+ Ok(format!("`{}`({})", name, section))
+ }
+}
+
+struct TextRenderer<'e> {
+ output: String,
+ indent: usize,
+ /// The current line being written. Once a line break is encountered (such
+ /// as starting a new paragraph), this will be written to `output` via
+ /// `flush`.
+ line: String,
+ /// The current word being written. Once a break is encountered (such as a
+ /// space) this will be written to `line` via `flush_word`.
+ word: String,
+ parser: EventIter<'e>,
+ /// The base URL used for relative URLs.
+ url: Option,
+ table: Table,
+}
+
+impl<'e> TextRenderer<'e> {
+ fn render(input: &str, url: Option, indent: usize) -> Result {
+ let parser = crate::md_parser(input, url.clone());
+ let output = String::with_capacity(input.len() * 3 / 2);
+ let mut mr = TextRenderer {
+ output,
+ indent,
+ line: String::new(),
+ word: String::new(),
+ parser,
+ url,
+ table: Table::new(),
+ };
+ mr.push_md()?;
+ Ok(mr.output)
+ }
+
+ fn push_md(&mut self) -> Result<(), Error> {
+ // If this is true, this is inside a cdata block used for hiding
+ // content from pulldown_cmark.
+ let mut in_cdata = false;
+ // The current list stack. None if unordered, Some if ordered with the
+ // given number as the current index.
+ let mut list: Vec
> = Vec::new();
+ // Used in some cases where spacing isn't desired.
+ let mut suppress_paragraph = false;
+ // Whether or not word-wrapping is enabled.
+ let mut wrap_text = true;
+
+ while let Some((event, range)) = self.parser.next() {
+ let this_suppress_paragraph = suppress_paragraph;
+ // Always reset suppression, even if the next event isn't a
+ // paragraph. This is in essence, a 1-token lookahead where the
+ // suppression is only enabled if the next event is a paragraph.
+ suppress_paragraph = false;
+ match event {
+ Event::Start(tag) => {
+ match tag {
+ Tag::Paragraph => {
+ if !this_suppress_paragraph {
+ self.flush();
+ }
+ }
+ Tag::Heading(n) => {
+ self.flush();
+ if n == 1 {
+ let text = header_text(&mut self.parser)?;
+ self.push_to_line(&text.to_uppercase());
+ self.hard_break();
+ self.hard_break();
+ } else if n == 2 {
+ let text = header_text(&mut self.parser)?;
+ self.push_to_line(&text.to_uppercase());
+ self.flush();
+ self.indent = 7;
+ } else {
+ let text = header_text(&mut self.parser)?;
+ self.push_indent((n as usize - 2) * 3);
+ self.push_to_line(&text);
+ self.flush();
+ self.indent = (n as usize - 1) * 3 + 1;
+ }
+ }
+ Tag::BlockQuote => {
+ self.indent += 3;
+ }
+ Tag::CodeBlock(_kind) => {
+ self.flush();
+ wrap_text = false;
+ self.indent += 4;
+ }
+ Tag::List(start) => list.push(start),
+ Tag::Item => {
+ self.flush();
+ match list.last_mut().expect("item must have list start") {
+ // Ordered list.
+ Some(n) => {
+ self.push_indent(self.indent);
+ write!(self.line, "{}.", n)?;
+ *n += 1;
+ }
+ // Unordered list.
+ None => {
+ self.push_indent(self.indent);
+ self.push_to_line("o ")
+ }
+ }
+ self.indent += 3;
+ suppress_paragraph = true;
+ }
+ Tag::FootnoteDefinition(_label) => unimplemented!(),
+ Tag::Table(alignment) => {
+ assert!(self.table.alignment.is_empty());
+ self.flush();
+ self.table.alignment.extend(alignment);
+ let table = self.table.process(&mut self.parser, self.indent)?;
+ self.output.push_str(&table);
+ self.hard_break();
+ self.table = Table::new();
+ }
+ Tag::TableHead | Tag::TableRow | Tag::TableCell => {
+ bail!("unexpected table element")
+ }
+ Tag::Emphasis => {}
+ Tag::Strong => {}
+ // Strikethrough isn't usually supported for TTY.
+ Tag::Strikethrough => self.word.push_str("~~"),
+ Tag::Link(link_type, dest_url, _title) => {
+ if dest_url.starts_with('#') {
+ // In a man page, page-relative anchors don't
+ // have much meaning.
+ continue;
+ }
+ match link_type {
+ LinkType::Autolink | LinkType::Email => {
+ // The text is a copy of the URL, which is not needed.
+ match self.parser.next() {
+ Some((Event::Text(_), _range)) => {}
+ _ => bail!("expected text after autolink"),
+ }
+ }
+ LinkType::Inline
+ | LinkType::Reference
+ | LinkType::Collapsed
+ | LinkType::Shortcut => {}
+ // This is currently unused. This is only
+ // emitted with a broken link callback, but I
+ // felt it is too annoying to escape `[` in
+ // option descriptions.
+ LinkType::ReferenceUnknown
+ | LinkType::CollapsedUnknown
+ | LinkType::ShortcutUnknown => {
+ bail!(
+ "link with missing reference `{}` located at offset {}",
+ dest_url,
+ range.start
+ );
+ }
+ }
+ }
+ Tag::Image(_link_type, _dest_url, _title) => {
+ bail!("images are not currently supported")
+ }
+ }
+ }
+ Event::End(tag) => match &tag {
+ Tag::Paragraph => {
+ self.flush();
+ self.hard_break();
+ }
+ Tag::Heading(_n) => {}
+ Tag::BlockQuote => {
+ self.indent -= 3;
+ }
+ Tag::CodeBlock(_kind) => {
+ self.hard_break();
+ wrap_text = true;
+ self.indent -= 4;
+ }
+ Tag::List(_) => {
+ list.pop();
+ }
+ Tag::Item => {
+ self.flush();
+ self.indent -= 3;
+ self.hard_break();
+ }
+ Tag::FootnoteDefinition(_label) => {}
+ Tag::Table(_) => {}
+ Tag::TableHead => {}
+ Tag::TableRow => {}
+ Tag::TableCell => {}
+ Tag::Emphasis => {}
+ Tag::Strong => {}
+ Tag::Strikethrough => self.word.push_str("~~"),
+ Tag::Link(link_type, dest_url, _title) => {
+ if dest_url.starts_with('#') {
+ continue;
+ }
+ match link_type {
+ LinkType::Autolink | LinkType::Email => {}
+ LinkType::Inline
+ | LinkType::Reference
+ | LinkType::Collapsed
+ | LinkType::Shortcut => self.flush_word(),
+ _ => {
+ panic!("unexpected tag {:?}", tag);
+ }
+ }
+ self.flush_word();
+ write!(self.word, "<{}>", dest_url)?;
+ }
+ Tag::Image(_link_type, _dest_url, _title) => {}
+ },
+ Event::Text(t) | Event::Code(t) => {
+ if wrap_text {
+ let chunks = split_chunks(&t);
+ for chunk in chunks {
+ if chunk == " " {
+ self.flush_word();
+ } else {
+ self.word.push_str(chunk);
+ }
+ }
+ } else {
+ for line in t.lines() {
+ self.push_indent(self.indent);
+ self.push_to_line(line);
+ self.flush();
+ }
+ }
+ }
+ Event::Html(t) => {
+ if t.starts_with("") {
+ in_cdata = false;
+ } else {
+ let trimmed = t.trim();
+ if trimmed.is_empty() {
+ continue;
+ }
+ if trimmed == " " {
+ self.hard_break();
+ } else if trimmed.starts_with("
+
+
+[bar]: https://example.com/bar
+[collapsed]: https://example.com/collapsed
+[shortcut]: https://example.com/shortcut
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/links.txt cargo-0.51.0/crates/mdman/tests/compare/expected/links.txt
--- cargo-0.47.0/crates/mdman/tests/compare/expected/links.txt 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/links.txt 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,40 @@
+LINKS(1)
+
+NAME
+ links - Test of different link kinds
+
+DESCRIPTION
+ Inline link: inline link
+
+ Reference link: this is a link
+
+ Collapsed: collapsed
+
+ Shortcut: shortcut
+
+ Autolink:
+
+ Email:
+
+ Relative link: relative link
+
+ Collapsed unknown: [collapsed unknown][]
+
+ Reference unknown: [foo][unknown]
+
+ Shortcut unknown: [shortcut unknown]
+
+ other-cmd(1)
+
+ local-cmd(1)
+
+ Some link
+
+ --include
+ Testing an included link .
+
+OPTIONS
+ --foo-bar
+ Example link . See other-cmd(1),
+ local-cmd(1)
+
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/options.1 cargo-0.51.0/crates/mdman/tests/compare/expected/options.1
--- cargo-0.47.0/crates/mdman/tests/compare/expected/options.1 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/options.1 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,94 @@
+'\" t
+.TH "MY\-COMMAND" "1"
+.nh
+.ad l
+.ss \n[.ss] 0
+.SH "NAME"
+my\-command \- A brief description
+.SH "SYNOPSIS"
+\fBmy\-command\fR [\fB\-\-abc\fR | \fB\-\-xyz\fR] \fIname\fR
+.br
+\fBmy\-command\fR [\fB\-f\fR \fIfile\fR]
+.br
+\fBmy\-command\fR (\fB\-m\fR | \fB\-M\fR) [\fIoldbranch\fR] \fInewbranch\fR
+.br
+\fBmy\-command\fR (\fB\-d\fR | \fB\-D\fR) [\fB\-r\fR] \fIbranchname\fR\&...
+.SH "DESCRIPTION"
+A description of the command.
+.sp
+.RS 4
+\h'-04'\(bu\h'+02'One
+.sp
+.RS 4
+\h'-04'\(bu\h'+02'Sub one
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+02'Sub two
+.RE
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+02'Two
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+02'Three
+.RE
+.SH "OPTIONS"
+.SS "Command options"
+.sp
+\fB\-\-foo\-bar\fR
+.RS 4
+Demo \fIemphasis\fR, \fBstrong\fR, ~~strike~~
+.RE
+.sp
+\fB\-p\fR \fIspec\fR,
+\fB\-\-package\fR \fIspec\fR
+.RS 4
+This has multiple flags.
+.RE
+.sp
+\fInamed\-arg...\fR
+.RS 4
+A named argument.
+.RE
+.SS "Common Options"
+.sp
+\fB@\fR\fIfilename\fR
+.RS 4
+Load from filename.
+.RE
+.sp
+\fB\-\-foo\fR [\fIbar\fR]
+.RS 4
+Flag with optional value.
+.RE
+.sp
+\fB\-\-foo\fR[\fB=\fR\fIbar\fR]
+.RS 4
+Alternate syntax for optional value (with required = for disambiguation).
+.RE
+.SH "EXAMPLES"
+.sp
+.RS 4
+\h'-04' 1.\h'+01'An example
+.sp
+.RS 4
+.nf
+my\-command \-\-abc
+.fi
+.RE
+.RE
+.sp
+.RS 4
+\h'-04' 2.\h'+01'Another example
+.sp
+.RS 4
+.nf
+my\-command \-\-xyz
+.fi
+.RE
+.RE
+.SH "SEE ALSO"
+\fBother\-command\fR(1) \fBabc\fR(7)
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/options.md cargo-0.51.0/crates/mdman/tests/compare/expected/options.md
--- cargo-0.47.0/crates/mdman/tests/compare/expected/options.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/options.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,77 @@
+# my-command(1)
+
+## NAME
+
+my-command - A brief description
+
+## SYNOPSIS
+
+`my-command` [`--abc` | `--xyz`] _name_\
+`my-command` [`-f` _file_]\
+`my-command` (`-m` | `-M`) [_oldbranch_] _newbranch_\
+`my-command` (`-d` | `-D`) [`-r`] _branchname_...
+
+## DESCRIPTION
+
+A description of the command.
+
+* One
+ * Sub one
+ * Sub two
+* Two
+* Three
+
+
+## OPTIONS
+
+### Command options
+
+
+
+
--foo-bar
+
Demo emphasis, strong, strike
+
+
+
-pspec
+
--packagespec
+
This has multiple flags.
+
+
+
named-arg...
+
A named argument.
+
+
+
+
+### Common Options
+
+
+
@filename
+
Load from filename.
+
+
+
--foo [bar]
+
Flag with optional value.
+
+
+
--foo[=bar]
+
Alternate syntax for optional value (with required = for disambiguation).
+
+
+
+
+
+## EXAMPLES
+
+1. An example
+
+ ```
+ my-command --abc
+ ```
+
+1. Another example
+
+ my-command --xyz
+
+## SEE ALSO
+[other-command(1)](other-command.html) [abc(7)](abc.html)
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/options.txt cargo-0.51.0/crates/mdman/tests/compare/expected/options.txt
--- cargo-0.47.0/crates/mdman/tests/compare/expected/options.txt 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/options.txt 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,57 @@
+MY-COMMAND(1)
+
+NAME
+ my-command - A brief description
+
+SYNOPSIS
+ my-command [--abc | --xyz] name
+ my-command [-f file]
+ my-command (-m | -M) [oldbranch] newbranch
+ my-command (-d | -D) [-r] branchname...
+
+DESCRIPTION
+ A description of the command.
+
+ o One
+ o Sub one
+
+ o Sub two
+
+ o Two
+
+ o Three
+
+OPTIONS
+ Command options
+ --foo-bar
+ Demo emphasis, strong, ~~strike~~
+
+ -p spec, --package spec
+ This has multiple flags.
+
+ named-arg...
+ A named argument.
+
+ Common Options
+ @filename
+ Load from filename.
+
+ --foo [bar]
+ Flag with optional value.
+
+ --foo[=bar]
+ Alternate syntax for optional value (with required = for
+ disambiguation).
+
+EXAMPLES
+ 1. An example
+
+ my-command --abc
+
+ 2. Another example
+
+ my-command --xyz
+
+SEE ALSO
+ other-command(1) abc(7)
+
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/tables.1 cargo-0.51.0/crates/mdman/tests/compare/expected/tables.1
--- cargo-0.47.0/crates/mdman/tests/compare/expected/tables.1 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/tables.1 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,108 @@
+'\" t
+.TH "TABLES" "1"
+.nh
+.ad l
+.ss \n[.ss] 0
+.SH "DESCRIPTION"
+Testing tables.
+
+.TS
+allbox tab(:);
+lt.
+T{
+Single col
+T}
+T{
+Hi! :)
+T}
+.TE
+.sp
+
+.TS
+allbox tab(:);
+lt lt lt.
+T{
+Header content
+T}:T{
+With \fBformat\fR \fItext\fR
+T}:T{
+Another column
+T}
+T{
+Some data
+T}:T{
+More data
+T}:T{
+
+T}
+T{
+Extra long amount of text within a column
+T}:T{
+hi
+T}:T{
+there
+T}
+.TE
+.sp
+
+.TS
+allbox tab(:);
+lt ct rt.
+T{
+Left aligned
+T}:T{
+Center aligned
+T}:T{
+Right aligned
+T}
+T{
+abc
+T}:T{
+def
+T}:T{
+ghi
+T}
+.TE
+.sp
+
+.TS
+allbox tab(:);
+lt ct rt.
+T{
+Left aligned
+T}:T{
+Center aligned
+T}:T{
+Right aligned
+T}
+T{
+X
+T}:T{
+X
+T}:T{
+X
+T}
+T{
+Extra long text 123456789012 with mixed widths.
+T}:T{
+Extra long text 123456789012 with mixed widths.
+T}:T{
+Extra long text 123456789012 with mixed widths.
+T}
+.TE
+.sp
+
+.TS
+allbox tab(:);
+lt.
+T{
+Link check
+T}
+T{
+\fIfoo\fR
+T}
+T{
+
+T}
+.TE
+.sp
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/tables.md cargo-0.51.0/crates/mdman/tests/compare/expected/tables.md
--- cargo-0.47.0/crates/mdman/tests/compare/expected/tables.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/tables.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,35 @@
+# tables(1)
+
+## DESCRIPTION
+
+Testing tables.
+
+| Single col |
+--------------
+| Hi! :) |
+
+
+Header content | With `format` *text* | Another column
+---------------|----------------------|----------------
+Some data | More data |
+Extra long amount of text within a column | hi | there
+
+
+Left aligned | Center aligned | Right aligned
+-------------|:--------------:|--------------:
+abc | def | ghi
+
+
+Left aligned | Center aligned | Right aligned
+-------------|:--------------:|--------------:
+X | X | X
+Extra long text 123456789012 with mixed widths. | Extra long text 123456789012 with mixed widths. | Extra long text 123456789012 with mixed widths.
+
+
+| Link check |
+--------------
+| [foo] |
+| |
+
+
+[foo]: https://example.com/
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/tables.txt cargo-0.51.0/crates/mdman/tests/compare/expected/tables.txt
--- cargo-0.47.0/crates/mdman/tests/compare/expected/tables.txt 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/tables.txt 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,45 @@
+TABLES(1)
+
+DESCRIPTION
+ Testing tables.
+
+ +-------------+
+ | Single col |
+ +-------------+
+ | Hi! :) |
+ +-------------+
+
+ +-------------------------------------+----------------+--------------+
+ | Header content | With format | Another |
+ | | text | column |
+ +-------------------------------------+----------------+--------------+
+ | Some data | More data | |
+ +-------------------------------------+----------------+--------------+
+ | Extra long amount of text within a | hi | there |
+ | column | | |
+ +-------------------------------------+----------------+--------------+
+
+ +---------------+-----------------+----------------+
+ | Left aligned | Center aligned | Right aligned |
+ +---------------+-----------------+----------------+
+ | abc | def | ghi |
+ +---------------+-----------------+----------------+
+
+ +-----------------------+-----------------------+-----------------------+
+ | Left aligned | Center aligned | Right aligned |
+ +-----------------------+-----------------------+-----------------------+
+ | X | X | X |
+ +-----------------------+-----------------------+-----------------------+
+ | Extra long text | Extra long text | Extra long text |
+ | 123456789012 with | 123456789012 with | 123456789012 with |
+ | mixed widths. | mixed widths. | mixed widths. |
+ +-----------------------+-----------------------+-----------------------+
+
+ +-----------------------+
+ | Link check |
+ +-----------------------+
+ | foo |
+ +-----------------------+
+ | https://example.com/ |
+ +-----------------------+
+
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/vars.7 cargo-0.51.0/crates/mdman/tests/compare/expected/vars.7
--- cargo-0.47.0/crates/mdman/tests/compare/expected/vars.7 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/vars.7 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,9 @@
+'\" t
+.TH "VARS" "7"
+.nh
+.ad l
+.ss \n[.ss] 0
+.sp
+Bar
+.sp
+bar
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/vars.md cargo-0.51.0/crates/mdman/tests/compare/expected/vars.md
--- cargo-0.47.0/crates/mdman/tests/compare/expected/vars.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/vars.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,7 @@
+# vars(7)
+
+
+
+Bar
+
+bar
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/expected/vars.txt cargo-0.51.0/crates/mdman/tests/compare/expected/vars.txt
--- cargo-0.47.0/crates/mdman/tests/compare/expected/vars.txt 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/expected/vars.txt 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,6 @@
+VARS(7)
+
+Bar
+
+bar
+
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/formatting.md cargo-0.51.0/crates/mdman/tests/compare/formatting.md
--- cargo-0.47.0/crates/mdman/tests/compare/formatting.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/formatting.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,94 @@
+# formatting(1)
+
+This is **nested _formatting_ `text`**.
+
+## SECOND HEADING
+
+Some text at second level.
+
+### Third heading
+
+Some text at third level.
+
+#### Fourth heading
+
+Some text at fourth level.
+
+## Quotes and blocks.
+
+Here are some quotes and blocks.
+
+> This is a block quote. Ambidextrously koala apart that prudent blindly alas
+> far amid dear goodness turgid so exact inside oh and alas much fanciful that
+> dark on spoon-fed adequately insolent walking crud.
+
+```
+This is a code block. Groundhog watchfully sudden firefly some self-consciously hotly jeepers satanic after that this parrot this at virtuous
+some mocking the leaned jeez nightingale as much mallard so because jeez
+turned dear crud grizzly strenuously.
+
+ Indented and should be unmodified.
+```
+
+ This is an indented code block. Egregiously yikes animatedly since outside beseechingly a badger hey shakily giraffe a one wow one this
+ goodness regarding reindeer so astride before.
+
+ Doubly indented
+
+## Lists
+
+1. Ordered list
+
+ * Unordered list
+
+ With a second paragraph inside it
+
+ 1. Inner ordered list
+
+ 1. Another
+
+ * Eggs
+
+ * Milk
+ 5. Don't start at one.
+ 6. tamarind
+
+1. Second element
+
+1. Third element
+
+## Breaks
+
+This has a\
+hard break in it
+and a soft one.
+
+## Horizontal rule
+
+This should contain a line:
+
+---
+
+Nice!
+
+## Strange characters
+
+Handles escaping for characters
+
+.dot at the start of a line.
+
+\fBnot really troff
+
+Various characters \ - – — ─ │ ├ └
+
+```
+tree
+└── example
+ ├── salamander
+ │ ├── honey
+ │ └── some
+ ├── fancifully
+ └── trout
+```
+
+ non-breaking space.
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/includes/links-include.md cargo-0.51.0/crates/mdman/tests/compare/includes/links-include.md
--- cargo-0.47.0/crates/mdman/tests/compare/includes/links-include.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/includes/links-include.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,7 @@
+[Some link](foo.html)
+
+{{#options}}
+{{#option "`--include`"}}
+Testing an [included link](included_link.html).
+{{/option}}
+{{/options}}
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/includes/options-common.md cargo-0.51.0/crates/mdman/tests/compare/includes/options-common.md
--- cargo-0.47.0/crates/mdman/tests/compare/includes/options-common.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/includes/options-common.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,14 @@
+{{#options}}
+{{#option "`@`_filename_"}}
+Load from filename.
+{{/option}}
+
+{{#option "`--foo` [_bar_]"}}
+Flag with optional value.
+{{/option}}
+
+{{#option "`--foo`[`=`_bar_]"}}
+Alternate syntax for optional value (with required = for disambiguation).
+{{/option}}
+
+{{/options}}
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/links.md cargo-0.51.0/crates/mdman/tests/compare/links.md
--- cargo-0.47.0/crates/mdman/tests/compare/links.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/links.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,49 @@
+# links(1)
+
+## NAME
+
+links - Test of different link kinds
+
+## DESCRIPTION
+
+Inline link: [inline link](https://example.com/inline)
+
+Reference link: [this is a link][bar]
+
+Collapsed: [collapsed][]
+
+Shortcut: [shortcut]
+
+Autolink:
+
+Email:
+
+Relative link: [relative link](foo/bar.html)
+
+Collapsed unknown: [collapsed unknown][]
+
+Reference unknown: [foo][unknown]
+
+Shortcut unknown: [shortcut unknown]
+
+{{man "other-cmd" 1}}
+
+{{man "local-cmd" 1}}
+
+{{> links-include}}
+
+## OPTIONS
+
+{{#options}}
+
+{{#option "`--foo-bar`"}}
+Example [link](bar.html).
+See {{man "other-cmd" 1}}, {{man "local-cmd" 1}}
+{{/option}}
+
+{{/options}}
+
+
+[bar]: https://example.com/bar
+[collapsed]: https://example.com/collapsed
+[shortcut]: https://example.com/shortcut
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/options.md cargo-0.51.0/crates/mdman/tests/compare/options.md
--- cargo-0.47.0/crates/mdman/tests/compare/options.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/options.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,62 @@
+# my-command(1)
+
+## NAME
+
+my-command - A brief description
+
+## SYNOPSIS
+
+`my-command` [`--abc` | `--xyz`] _name_\
+`my-command` [`-f` _file_]\
+`my-command` (`-m` | `-M`) [_oldbranch_] _newbranch_\
+`my-command` (`-d` | `-D`) [`-r`] _branchname_...
+
+## DESCRIPTION
+
+A description of the command.
+
+* One
+ * Sub one
+ * Sub two
+* Two
+* Three
+
+
+## OPTIONS
+
+### Command options
+
+{{#options}}
+
+{{#option "`--foo-bar`"}}
+Demo *emphasis*, **strong**, ~~strike~~
+{{/option}}
+
+{{#option "`-p` _spec_" "`--package` _spec_"}}
+This has multiple flags.
+{{/option}}
+
+{{#option "_named-arg..._"}}
+A named argument.
+{{/option}}
+
+{{/options}}
+
+### Common Options
+
+{{> options-common}}
+
+## EXAMPLES
+
+1. An example
+
+ ```
+ my-command --abc
+ ```
+
+1. Another example
+
+ my-command --xyz
+
+## SEE ALSO
+{{man "other-command" 1}} {{man "abc" 7}}
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/tables.md cargo-0.51.0/crates/mdman/tests/compare/tables.md
--- cargo-0.47.0/crates/mdman/tests/compare/tables.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/tables.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,35 @@
+# tables(1)
+
+## DESCRIPTION
+
+Testing tables.
+
+| Single col |
+--------------
+| Hi! :) |
+
+
+Header content | With `format` *text* | Another column
+---------------|----------------------|----------------
+Some data | More data |
+Extra long amount of text within a column | hi | there
+
+
+Left aligned | Center aligned | Right aligned
+-------------|:--------------:|--------------:
+abc | def | ghi
+
+
+Left aligned | Center aligned | Right aligned
+-------------|:--------------:|--------------:
+X | X | X
+Extra long text 123456789012 with mixed widths. | Extra long text 123456789012 with mixed widths. | Extra long text 123456789012 with mixed widths.
+
+
+| Link check |
+--------------
+| [foo] |
+| |
+
+
+[foo]: https://example.com/
diff -Nru cargo-0.47.0/crates/mdman/tests/compare/vars.md cargo-0.51.0/crates/mdman/tests/compare/vars.md
--- cargo-0.47.0/crates/mdman/tests/compare/vars.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare/vars.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,7 @@
+# vars(7)
+
+{{*set foo="Bar"}}
+
+{{foo}}
+
+{{lower foo}}
diff -Nru cargo-0.47.0/crates/mdman/tests/compare.rs cargo-0.51.0/crates/mdman/tests/compare.rs
--- cargo-0.47.0/crates/mdman/tests/compare.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/compare.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,48 @@
+//! Compares input to expected output.
+//!
+//! Use the MDMAN_BLESS environment variable to automatically update the
+//! expected output.
+
+use mdman::{Format, ManMap};
+use pretty_assertions::assert_eq;
+use std::path::PathBuf;
+use url::Url;
+
+fn run(name: &str) {
+ let input = PathBuf::from(format!("tests/compare/{}.md", name));
+ let url = Some(Url::parse("https://example.org/").unwrap());
+ let mut map = ManMap::new();
+ map.insert(
+ ("other-cmd".to_string(), 1),
+ "https://example.org/commands/other-cmd.html".to_string(),
+ );
+
+ for &format in &[Format::Man, Format::Md, Format::Text] {
+ let section = mdman::extract_section(&input).unwrap();
+ let result = mdman::convert(&input, format, url.clone(), map.clone()).unwrap();
+ let expected_path = format!(
+ "tests/compare/expected/{}.{}",
+ name,
+ format.extension(section)
+ );
+ if std::env::var("MDMAN_BLESS").is_ok() {
+ std::fs::write(&expected_path, result).unwrap();
+ } else {
+ let expected = std::fs::read_to_string(&expected_path).unwrap();
+ // Fix if Windows checked out with autocrlf.
+ let expected = expected.replace("\r\n", "\n");
+ assert_eq!(expected, result);
+ }
+ }
+}
+
+macro_rules! test( ($name:ident) => (
+ #[test]
+ fn $name() { run(stringify!($name)); }
+) );
+
+test!(formatting);
+test!(links);
+test!(options);
+test!(tables);
+test!(vars);
diff -Nru cargo-0.47.0/crates/mdman/tests/invalid/nested.md cargo-0.51.0/crates/mdman/tests/invalid/nested.md
--- cargo-0.47.0/crates/mdman/tests/invalid/nested.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/invalid/nested.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,6 @@
+# nested(1)
+
+{{#options}}
+{{#options}}
+{{/options}}
+{{/options}}
diff -Nru cargo-0.47.0/crates/mdman/tests/invalid/not-inside-options.md cargo-0.51.0/crates/mdman/tests/invalid/not-inside-options.md
--- cargo-0.47.0/crates/mdman/tests/invalid/not-inside-options.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/invalid/not-inside-options.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,5 @@
+# not-inside-options(1)
+
+{{#option "`-o`"}}
+Testing without options block.
+{{/option}}
diff -Nru cargo-0.47.0/crates/mdman/tests/invalid.rs cargo-0.51.0/crates/mdman/tests/invalid.rs
--- cargo-0.47.0/crates/mdman/tests/invalid.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/crates/mdman/tests/invalid.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,34 @@
+//! Tests for errors and invalid input.
+
+use mdman::{Format, ManMap};
+use pretty_assertions::assert_eq;
+use std::path::PathBuf;
+
+fn run(name: &str, expected_error: &str) {
+ let input = PathBuf::from(format!("tests/invalid/{}", name));
+ match mdman::convert(&input, Format::Man, None, ManMap::new()) {
+ Ok(_) => {
+ panic!("expected {} to fail", name);
+ }
+ Err(e) => {
+ assert_eq!(expected_error, e.to_string());
+ }
+ }
+}
+
+macro_rules! test( ($name:ident, $file_name:expr, $error:expr) => (
+ #[test]
+ fn $name() { run($file_name, $error); }
+) );
+
+test!(
+ nested,
+ "nested.md",
+ "Error rendering \"template\" line 4, col 1: options blocks cannot be nested"
+);
+
+test!(
+ not_inside_options,
+ "not-inside-options.md",
+ "Error rendering \"template\" line 3, col 1: option must be in options block"
+);
diff -Nru cargo-0.47.0/crates/resolver-tests/src/lib.rs cargo-0.51.0/crates/resolver-tests/src/lib.rs
--- cargo-0.47.0/crates/resolver-tests/src/lib.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/crates/resolver-tests/src/lib.rs 2021-02-04 15:18:32.000000000 +0000
@@ -24,7 +24,7 @@
use varisat::{self, ExtendFormula};
pub fn resolve(deps: Vec, registry: &[Summary]) -> CargoResult> {
- resolve_with_config(deps, registry, None)
+ resolve_with_config(deps, registry, &Config::default().unwrap())
}
pub fn resolve_and_validated(
@@ -32,7 +32,7 @@
registry: &[Summary],
sat_resolve: Option,
) -> CargoResult> {
- let resolve = resolve_with_config_raw(deps.clone(), registry, None);
+ let resolve = resolve_with_config_raw(deps.clone(), registry, &Config::default().unwrap());
match resolve {
Err(e) => {
@@ -109,7 +109,7 @@
pub fn resolve_with_config(
deps: Vec,
registry: &[Summary],
- config: Option<&Config>,
+ config: &Config,
) -> CargoResult> {
let resolve = resolve_with_config_raw(deps, registry, config)?;
Ok(resolve.sort())
@@ -118,7 +118,7 @@
pub fn resolve_with_config_raw(
deps: Vec,
registry: &[Summary],
- config: Option<&Config>,
+ config: &Config,
) -> CargoResult {
struct MyRegistry<'a> {
list: &'a [Summary],
@@ -171,11 +171,11 @@
used: HashSet::new(),
};
let summary = Summary::new(
+ config,
pkg_id("root"),
deps,
- &BTreeMap::>::new(),
+ &BTreeMap::new(),
None::<&String>,
- false,
)
.unwrap();
let opts = ResolveOpts::everything();
@@ -185,7 +185,7 @@
&[],
&mut registry,
&HashSet::new(),
- config,
+ Some(config),
true,
);
@@ -572,11 +572,11 @@
None
};
Summary::new(
+ &Config::default().unwrap(),
name.to_pkgid(),
dep,
- &BTreeMap::>::new(),
+ &BTreeMap::new(),
link,
- false,
)
.unwrap()
}
@@ -600,11 +600,11 @@
None
};
Summary::new(
+ &Config::default().unwrap(),
pkg_id_loc(name, loc),
Vec::new(),
- &BTreeMap::>::new(),
+ &BTreeMap::new(),
link,
- false,
)
.unwrap()
}
@@ -614,11 +614,11 @@
deps.remove(ind);
// note: more things will need to be copied over in the future, but it works for now.
Summary::new(
+ &Config::default().unwrap(),
sum.package_id(),
deps,
- &BTreeMap::>::new(),
+ &BTreeMap::new(),
sum.links().map(|a| a.as_str()),
- sum.namespaced_features(),
)
.unwrap()
}
diff -Nru cargo-0.47.0/crates/resolver-tests/tests/resolve.rs cargo-0.51.0/crates/resolver-tests/tests/resolve.rs
--- cargo-0.47.0/crates/resolver-tests/tests/resolve.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/crates/resolver-tests/tests/resolve.rs 2021-02-04 15:18:32.000000000 +0000
@@ -87,7 +87,7 @@
let mres = resolve_with_config(
vec![dep_req(&this.name(), &format!("={}", this.version()))],
®,
- Some(&config),
+ &config,
);
prop_assert_eq!(
@@ -228,6 +228,7 @@
}
#[test]
+#[should_panic(expected = "pub dep")] // The error handling is not yet implemented.
fn pub_fail() {
let input = vec![
pkg!(("a", "0.0.4")),
@@ -583,7 +584,7 @@
let res = resolve_with_config(
vec![dep_req("foo", "1.0.0"), dep_req("bar", "1.0.0")],
®,
- Some(&config),
+ &config,
)
.unwrap();
diff -Nru cargo-0.47.0/debian/changelog cargo-0.51.0/debian/changelog
--- cargo-0.47.0/debian/changelog 2020-12-10 07:42:47.000000000 +0000
+++ cargo-0.51.0/debian/changelog 2021-04-19 23:09:04.000000000 +0000
@@ -1,8 +1,56 @@
-cargo (0.47.0-1~exp1ubuntu1~20.10.1) groovy; urgency=medium
+cargo (0.51.0-0ubuntu1~20.10.1) groovy; urgency=medium
- * Backport to Groovy. (LP: #1901571)
+ * Backport to Groovy. (LP: #1915722)
+ * Embed libgit2 at the revision which is embedded by the libgit2-sys
+ crate, version 0.12.18+1.1.0 (which is not exactly libgit2 1.1.0,
+ confusingly)
+ - add debian/libgit2
+ - add debian/patches/use-system-libhttp-parser.patch
+ - update debian/control
+ - update debian/copyright
+ - update debiab/patches/series
+ - update debian/README.source
+ - update debian/rules
+
+ -- Michael Hudson-Doyle Tue, 20 Apr 2021 11:09:04 +1200
+
+cargo (0.51.0-0ubuntu1) hirsute; urgency=medium
+
+ * Merge from Debian unstable. Remaining changes:
+ - Don't use the bootstrap.py script for bootstrapping as it no longer
+ works.
+ - remove debian/bootstrap.py
+ - update debian/make_orig_multi.sh
+ * New upstream release. (LP: #1915722)
+ * Dropped changes:
+ - Embed libgit2 1.0.0 which is not yet in Debian or Ubuntu. (Hirsute
+ has a new enough libgit2)
+ - d/patches/0001-relax-deprecated-diagnostic-message-check.patch,
+ d/patches/u-8713.patch: included in upstream release.
+ * d/patches/skip-filter_platform-non-amd64.patch: skip a test that fails on
+ non amd64 platforms, see https://github.com/rust-lang/cargo/issues/9238.
- -- Michael Hudson-Doyle Thu, 10 Dec 2020 20:42:47 +1300
+ -- Michael Hudson-Doyle Mon, 08 Mar 2021 09:10:26 +1300
+
+cargo (0.47.0-3) unstable; urgency=medium
+
+ * Disable close_output test for now, it is flaky. This is a test problem not
+ a cargo problem and will be re-enabled in 0.49.0.
+
+ -- Ximin Luo Tue, 08 Dec 2020 01:43:58 +0000
+
+cargo (0.47.0-2) unstable; urgency=medium
+
+ * Backport a patch to fix a test on i386.
+ * Add +xgot to work around mips64el limitations.
+
+ -- Ximin Luo Tue, 08 Dec 2020 00:29:08 +0000
+
+cargo (0.47.0-1) unstable; urgency=medium
+
+ * Upload to unstable. (Closes: #976434)
+
+ -- Ximin Luo Sun, 06 Dec 2020 12:39:49 +0000
cargo (0.47.0-1~exp1ubuntu1) hirsute; urgency=medium
@@ -49,6 +97,13 @@
-- Michael Hudson-Doyle Wed, 24 Jun 2020 12:40:56 +1200
+cargo (0.43.1-4) unstable; urgency=medium
+
+ * Team upload.
+ * Fix build by applying two upstream patches. (Closes: #975857)
+
+ -- Jan Niehusmann Sat, 28 Nov 2020 11:07:20 +0100
+
cargo (0.43.1-3ubuntu1) groovy; urgency=medium
* Merge from Debian unstable (LP: #1876942): Remaining changes:
@@ -1425,4 +1480,3 @@
* Initial Debian release. (Closes: #786432)
-- Luca Bruno Tue, 11 Aug 2015 20:15:54 +0200
-
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/bash.yml cargo-0.51.0/debian/libgit2/azure-pipelines/bash.yml
--- cargo-0.47.0/debian/libgit2/azure-pipelines/bash.yml 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/bash.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,17 +0,0 @@
-# These are the steps used for building on machines with bash.
-steps:
-- bash: . '$(Build.SourcesDirectory)/azure-pipelines/build.sh'
- displayName: Build
- workingDirectory: '$(Build.BinariesDirectory)'
- env: ${{ parameters.environmentVariables }}
-- bash: . '$(Build.SourcesDirectory)/azure-pipelines/test.sh'
- displayName: Test
- workingDirectory: '$(Build.BinariesDirectory)'
- env: ${{ parameters.environmentVariables }}
-- task: PublishTestResults@2
- displayName: Publish Test Results
- condition: succeededOrFailed()
- inputs:
- testResultsFiles: 'results_*.xml'
- searchFolder: '$(Build.BinariesDirectory)'
- mergeTestResults: true
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/build.sh cargo-0.51.0/debian/libgit2/azure-pipelines/build.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/build.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/build.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,56 +0,0 @@
-#!/usr/bin/env bash
-#
-# Environment variables:
-#
-# SOURCE_DIR: Set to the directory of the libgit2 source (optional)
-# If not set, it will be derived relative to this script.
-
-set -e
-
-SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
-BUILD_DIR=$(pwd)
-BUILD_PATH=${BUILD_PATH:=$PATH}
-CMAKE=$(which cmake)
-CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
-
-indent() { sed "s/^/ /"; }
-
-echo "Source directory: ${SOURCE_DIR}"
-echo "Build directory: ${BUILD_DIR}"
-echo ""
-
-if [ "$(uname -s)" = "Darwin" ]; then
- echo "macOS version:"
- sw_vers | indent
-fi
-
-if [ -f "/etc/debian_version" ]; then
- echo "Debian version:"
- (source /etc/lsb-release && echo "${DISTRIB_DESCRIPTION}") | indent
-fi
-
-echo "Kernel version:"
-uname -a 2>&1 | indent
-
-echo "CMake version:"
-env PATH="$BUILD_PATH" "$CMAKE" --version 2>&1 | indent
-
-if test -n "$CC"; then
- echo "Compiler version:"
- "$CC" --version 2>&1 | indent
-fi
-echo ""
-
-echo "##############################################################################"
-echo "## Configuring build environment"
-echo "##############################################################################"
-
-echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS}
-env PATH="$BUILD_PATH" "$CMAKE" ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS}
-
-echo ""
-echo "##############################################################################"
-echo "## Building libgit2"
-echo "##############################################################################"
-
-env PATH="$BUILD_PATH" "$CMAKE" --build .
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/coverity.sh cargo-0.51.0/debian/libgit2/azure-pipelines/coverity.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/coverity.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/coverity.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,62 +0,0 @@
-#!/bin/bash -e
-
-if test -z "$COVERITY_TOKEN"
-then
- echo "Need to set a coverity token"
- exit 1
-fi
-
-case $(uname -m) in
- i?86)
- BITS=32;;
- amd64|x86_64)
- BITS=64;;
- *)
- echo "Unsupported arch '$(uname -m)'"
- exit 1;;
-esac
-
-SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS}
-SOURCE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)
-BUILD_DIR=${SOURCE_DIR}/coverity-build
-TOOL_DIR=${BUILD_DIR}/coverity-tools
-
-# Install coverity tools
-if ! test -d "$TOOL_DIR"
-then
- mkdir -p "$TOOL_DIR"
- curl --silent --show-error --location --data "project=libgit2&token=$COVERITY_TOKEN" "$SCAN_TOOL" |
- tar -xzC "$TOOL_DIR"
- ln -s "$(find "$TOOL_DIR" -type d -name 'cov-analysis*')" "$TOOL_DIR"/cov-analysis
-fi
-
-cp "${SOURCE_DIR}/script/user_nodefs.h" "$TOOL_DIR"/cov-analysis/config/
-
-# Build libgit2 with Coverity
-mkdir -p "$BUILD_DIR"
-cd "$BUILD_DIR"
-cmake "$SOURCE_DIR"
-COVERITY_UNSUPPORTED=1 \
- "$TOOL_DIR/cov-analysis/bin/cov-build" --dir cov-int \
- cmake --build .
-
-# Upload results
-tar -czf libgit2.tgz cov-int
-REVISION=$(cd ${SOURCE_DIR} && git rev-parse --short HEAD)
-HTML="$(curl \
- --silent --show-error \
- --write-out "\n%{http_code}" \
- --form token="$COVERITY_TOKEN" \
- --form email=libgit2@gmail.com \
- --form file=@libgit2.tgz \
- --form version="$REVISION" \
- --form description="libgit2 build" \
- https://scan.coverity.com/builds?project=libgit2)"
-
-# Status code is the last line
-STATUS_CODE="$(echo "$HTML" | tail -n1)"
-if test "${STATUS_CODE}" != 200 && test "${STATUS_CODE}" != 201
-then
- echo "Received error code ${STATUS_CODE} from Coverity"
- exit 1
-fi
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/coverity.yml cargo-0.51.0/debian/libgit2/azure-pipelines/coverity.yml
--- cargo-0.47.0/debian/libgit2/azure-pipelines/coverity.yml 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/coverity.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,26 +0,0 @@
-resources:
-- repo: self
-
-jobs:
-- job: coverity
- displayName: 'Coverity'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - script: |
- cd $(Build.SourcesDirectory)/azure-pipelines/docker
- docker build -t libgit2/xenial --build-arg BASE=ubuntu:xenial -f xenial .
- displayName: 'Build Docker image'
- - task: Docker@0
- displayName: Analyze
- inputs:
- action: 'Run an image'
- imageName: libgit2/xenial
- volumes: |
- $(Build.SourcesDirectory):/home/libgit2/source
- $(Build.BinariesDirectory):/home/libgit2/build
- envVars: |
- COVERITY_TOKEN=$(COVERITY_TOKEN)
- workDir: '/home/libgit2/build'
- containerCommand: '/home/libgit2/source/azure-pipelines/coverity.sh'
- detached: false
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/docker/bionic cargo-0.51.0/debian/libgit2/azure-pipelines/docker/bionic
--- cargo-0.47.0/debian/libgit2/azure-pipelines/docker/bionic 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/docker/bionic 1970-01-01 00:00:00.000000000 +0000
@@ -1,42 +0,0 @@
-ARG BASE
-FROM $BASE AS apt
-RUN apt-get update && \
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
- clang \
- cmake \
- curl \
- gcc \
- git \
- libcurl4-openssl-dev \
- libpcre3-dev \
- libssh2-1-dev \
- libssl-dev \
- libz-dev \
- ninja-build \
- openjdk-8-jre-headless \
- openssh-server \
- openssl \
- pkgconf \
- python \
- sudo \
- valgrind \
- && \
- rm -rf /var/lib/apt/lists/*
-
-FROM apt AS mbedtls
-RUN cd /tmp && \
- curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \
- tar -xz && \
- cd mbedtls-2.16.2 && \
- scripts/config.pl set MBEDTLS_MD4_C 1 && \
- CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
- ninja install && \
- cd .. && \
- rm -rf mbedtls-2.16.2
-
-FROM mbedtls AS configure
-COPY entrypoint.sh /usr/local/bin/entrypoint.sh
-RUN chmod a+x /usr/local/bin/entrypoint.sh
-RUN mkdir /var/run/sshd
-
-ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/docker/docurium cargo-0.51.0/debian/libgit2/azure-pipelines/docker/docurium
--- cargo-0.47.0/debian/libgit2/azure-pipelines/docker/docurium 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/docker/docurium 1970-01-01 00:00:00.000000000 +0000
@@ -1,3 +0,0 @@
-FROM ubuntu:bionic
-RUN apt update && apt install -y cmake pkg-config ruby ruby-dev llvm libclang-dev libssl-dev python-pygments
-RUN gem install docurium
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/docker/entrypoint.sh cargo-0.51.0/debian/libgit2/azure-pipelines/docker/entrypoint.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/docker/entrypoint.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/docker/entrypoint.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,4 +0,0 @@
-#!/bin/bash -e
-useradd --shell /bin/bash libgit2
-chown --recursive libgit2:libgit2 /home/libgit2
-exec sudo --preserve-env --set-home --user=libgit2 "$@"
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/docker/xenial cargo-0.51.0/debian/libgit2/azure-pipelines/docker/xenial
--- cargo-0.47.0/debian/libgit2/azure-pipelines/docker/xenial 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/docker/xenial 1970-01-01 00:00:00.000000000 +0000
@@ -1,67 +0,0 @@
-ARG BASE
-FROM $BASE AS apt
-RUN apt-get update && \
- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
- bzip2 \
- clang \
- cmake \
- curl \
- gcc \
- git \
- krb5-user \
- libcurl4-gnutls-dev \
- libgcrypt20-dev \
- libkrb5-dev \
- libpcre3-dev \
- libssl-dev \
- libz-dev \
- make \
- ninja-build \
- openjdk-8-jre-headless \
- openssh-server \
- openssl \
- pkgconf \
- python \
- sudo \
- valgrind \
- && \
- rm -rf /var/lib/apt/lists/*
-
-FROM apt AS mbedtls
-RUN cd /tmp && \
- curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \
- tar -xz && \
- cd mbedtls-2.16.2 && \
- scripts/config.pl set MBEDTLS_MD4_C 1 && \
- CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
- ninja install && \
- cd .. && \
- rm -rf mbedtls-2.16.2
-
-FROM mbedtls AS libssh2
-RUN cd /tmp && \
- curl --insecure --location --silent --show-error https://www.libssh2.org/download/libssh2-1.8.2.tar.gz | \
- tar -xz && \
- cd libssh2-1.8.2 && \
- CFLAGS=-fPIC cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=Libgcrypt . && \
- ninja install && \
- cd .. && \
- rm -rf libssh2-1.8.2
-
-FROM libssh2 AS valgrind
-RUN cd /tmp && \
- curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2 | \
- tar -xj && \
- cd valgrind-3.15.0 && \
- ./configure && \
- make && \
- make install && \
- cd .. && \
- rm -rf valgrind-3.15.0
-
-FROM valgrind AS configure
-COPY entrypoint.sh /usr/local/bin/entrypoint.sh
-RUN chmod a+x /usr/local/bin/entrypoint.sh
-RUN mkdir /var/run/sshd
-
-ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/docker.yml cargo-0.51.0/debian/libgit2/azure-pipelines/docker.yml
--- cargo-0.47.0/debian/libgit2/azure-pipelines/docker.yml 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/docker.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,51 +0,0 @@
-# These are the steps used in a container-based build in VSTS.
-steps:
-- ${{ if eq(parameters.qemu, 'true') }}:
- - script: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- displayName: 'Register Docker QEMU'
-
-- task: cache@2
- displayName: Cache Docker layers
- inputs:
- key: docker
- path: /tmp/dockercache
-- script: |
- if [ -f /tmp/dockercache/${{parameters.docker.image}}.tar ]; then docker load < /tmp/dockercache/${{parameters.docker.image}}.tar; fi
- displayName: 'Load Docker cache'
-- script: |
- cd $(Build.SourcesDirectory)/azure-pipelines/docker &&
- docker build -t libgit2/${{parameters.docker.image}} --build-arg BASE=${{parameters.docker.base}} -f ${{parameters.docker.image}} . &&
- if [ ! -d /tmp/dockercache ]; then mkdir /tmp/dockercache; fi &&
- docker save libgit2/${{parameters.docker.image}} $(docker history -q libgit2/${{parameters.docker.image}} | grep -v '') > /tmp/dockercache/${{parameters.docker.image}}.tar
- displayName: 'Build Docker image'
-- task: docker@0
- displayName: Build
- inputs:
- action: 'Run an image'
- imageName: libgit2/${{ parameters.docker.image }}
- volumes: |
- $(Build.SourcesDirectory):/home/libgit2/source
- $(Build.BinariesDirectory):/home/libgit2/build
- envVars: ${{ parameters.environmentVariables }}
- workDir: '/home/libgit2/build'
- containerCommand: '/home/libgit2/source/azure-pipelines/build.sh'
- detached: false
-- task: docker@0
- displayName: Test
- inputs:
- action: 'Run an image'
- imageName: libgit2/${{ parameters.docker.image }}
- volumes: |
- $(Build.SourcesDirectory):/home/libgit2/source
- $(Build.BinariesDirectory):/home/libgit2/build
- envVars: ${{ parameters.environmentVariables }}
- workDir: '/home/libgit2/build'
- containerCommand: '/home/libgit2/source/azure-pipelines/test.sh'
- detached: false
-- task: publishtestresults@2
- displayName: Publish Test Results
- condition: succeededOrFailed()
- inputs:
- testResultsFiles: 'results_*.xml'
- searchFolder: '$(Build.BinariesDirectory)'
- mergeTestResults: true
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/nightly.yml cargo-0.51.0/debian/libgit2/azure-pipelines/nightly.yml
--- cargo-0.47.0/debian/libgit2/azure-pipelines/nightly.yml 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/nightly.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,219 +0,0 @@
-resources:
-- repo: self
-
-jobs:
-- job: linux_amd64_xenial_gcc_openssl
- displayName: 'Linux (amd64; Xenial; GCC; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: linux_amd64_xenial_gcc_mbedtls
- displayName: 'Linux (amd64; Xenial; GCC; mbedTLS)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: linux_amd64_xenial_clang_openssl
- displayName: 'Linux (amd64; Xenial; Clang; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=clang
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: linux_amd64_xenial_clang_mbedtls
- displayName: 'Linux (amd64; Xenial; Clang; mbedTLS)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=clang
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: macos
- displayName: 'macOS (amd64; 10.15)'
- pool:
- vmImage: 'macOS-10.15'
- steps:
- - bash: . '$(Build.SourcesDirectory)/azure-pipelines/setup-osx.sh'
- displayName: Setup
- - template: bash.yml
- parameters:
- environmentVariables:
- TMPDIR: $(Agent.TempDirectory)
- PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
- CMAKE_GENERATOR: Ninja
- CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
- RUN_INVASIVE_TESTS: true
- SKIP_SSH_TESTS: true
-
-- job: windows_vs_amd64
- displayName: 'Windows (amd64; Visual Studio)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - template: bash.yml
- parameters:
- environmentVariables:
- CMAKE_GENERATOR: Visual Studio 15 2017
- CMAKE_OPTIONS: -A x64 -DMSVC_CRTDBG=ON -DDEPRECATE_HARD=ON
- RUN_INVASIVE_TESTS: true
- SKIP_SSH_TESTS: true
-
-- job: windows_vs_x86
- displayName: 'Windows (x86; Visual Studio)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - template: bash.yml
- parameters:
- environmentVariables:
- CMAKE_GENERATOR: Visual Studio 15 2017
- CMAKE_OPTIONS: -A Win32 -DMSVC_CRTDBG=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS
- RUN_INVASIVE_TESTS: true
- SKIP_SSH_TESTS: true
-
-- job: windows_mingw_amd64
- displayName: 'Windows (amd64; MinGW)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - bash: . '$(Build.SourcesDirectory)\azure-pipelines\setup-mingw.sh'
- displayName: Setup
- env:
- TEMP: $(Agent.TempDirectory)
- ARCH: amd64
- - template: bash.yml
- parameters:
- environmentVariables:
- BUILD_PATH: $(Agent.TempDirectory)\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
- CMAKE_GENERATOR: MinGW Makefiles
- CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
- RUN_INVASIVE_TESTS: true
- SKIP_SSH_TESTS: true
-
-- job: windows_mingw_x86
- displayName: 'Windows (x86; MinGW)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - bash: . '$(Build.SourcesDirectory)\azure-pipelines\setup-mingw.sh'
- displayName: Setup
- workingDirectory: '$(Build.BinariesDirectory)'
- env:
- TEMP: $(Agent.TempDirectory)
- ARCH: x86
- - template: bash.yml
- parameters:
- environmentVariables:
- BUILD_PATH: $(Agent.TempDirectory)\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
- CMAKE_GENERATOR: MinGW Makefiles
- CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
- RUN_INVASIVE_TESTS: true
- SKIP_SSH_TESTS: true
-
-- job: linux_x86_bionic_gcc_openssl
- displayName: 'Linux (x86; Bionic; GCC; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- qemu: 'true'
- docker:
- image: bionic
- base: multiarch/ubuntu-core:x86-bionic
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: linux_x86_bionic_clang_openssl
- displayName: 'Linux (x86; Bionic; Clang; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- qemu: 'true'
- docker:
- image: bionic
- base: multiarch/ubuntu-core:x86-bionic
- environmentVariables: |
- CC=clang
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind
- RUN_INVASIVE_TESTS=true
-
-- job: linux_arm32_bionic_gcc_openssl
- displayName: 'Linux (arm32; Bionic; GCC; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- qemu: 'true'
- docker:
- image: bionic
- base: multiarch/ubuntu-core:armhf-bionic
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON
- RUN_INVASIVE_TESTS=true
- SKIP_PROXY_TESTS=true
-
-- job: linux_arm64_bionic_gcc_openssl
- displayName: 'Linux (arm64; Bionic; GCC; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: docker.yml
- parameters:
- qemu: 'true'
- docker:
- image: bionic
- base: multiarch/ubuntu-core:arm64-bionic
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON
- RUN_INVASIVE_TESTS=true
- SKIP_PROXY_TESTS=true
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/setup-mingw.sh cargo-0.51.0/debian/libgit2/azure-pipelines/setup-mingw.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/setup-mingw.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/setup-mingw.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,15 +0,0 @@
-#!/bin/sh -e
-
-echo "##############################################################################"
-echo "## Downloading mingw"
-echo "##############################################################################"
-
-case "$ARCH" in
- amd64)
- MINGW_URI="https://bintray.com/libgit2/build-dependencies/download_file?file_path=mingw-w64-x86_64-8.1.0-release-win32-seh-rt_v6-rev0.zip";;
- x86)
- MINGW_URI="https://bintray.com/libgit2/build-dependencies/download_file?file_path=mingw-w64-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
-esac
-
-curl -s -L "$MINGW_URI" -o "$TEMP"/mingw-"$ARCH".zip
-unzip -q "$TEMP"/mingw-"$ARCH".zip -d "$TEMP"
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/setup-osx.sh cargo-0.51.0/debian/libgit2/azure-pipelines/setup-osx.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/setup-osx.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/setup-osx.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-set -x
-
-brew update
-brew install pkgconfig zlib curl openssl libssh2 ninja
-
-ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib /usr/local/lib
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines/test.sh cargo-0.51.0/debian/libgit2/azure-pipelines/test.sh
--- cargo-0.47.0/debian/libgit2/azure-pipelines/test.sh 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines/test.sh 1970-01-01 00:00:00.000000000 +0000
@@ -1,325 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-if [ -n "$SKIP_TESTS" ]; then
- exit 0
-fi
-
-# Windows doesn't run the NTLM tests properly (yet)
-if [[ "$(uname -s)" == MINGW* ]]; then
- SKIP_NTLM_TESTS=1
-fi
-
-SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
-BUILD_DIR=$(pwd)
-TMPDIR=${TMPDIR:-/tmp}
-USER=${USER:-$(whoami)}
-
-SUCCESS=1
-
-cleanup() {
- echo "Cleaning up..."
-
- if [ ! -z "$GITDAEMON_PID" ]; then
- echo "Stopping git daemon..."
- kill $GITDAEMON_PID
- fi
-
- if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
- echo "Stopping SSH..."
- kill $(cat "${SSHD_DIR}/pid")
- fi
-
- echo "Done."
-}
-
-run_test() {
- if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
- ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
- else
- ATTEMPTS_REMAIN=1
- fi
-
- FAILED=0
- while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
- if [ "$FAILED" -eq 1 ]; then
- echo ""
- echo "Re-running flaky ${1} tests..."
- echo ""
- fi
-
- RETURN_CODE=0
-
- CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
-
- if [ "$RETURN_CODE" -eq 0 ]; then
- FAILED=0
- break
- fi
-
- echo "Test exited with code: $RETURN_CODE"
- ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
- FAILED=1
- done
-
- if [ "$FAILED" -ne 0 ]; then
- SUCCESS=0
- fi
-}
-
-# Configure the test environment; run them early so that we're certain
-# that they're started by the time we need them.
-
-echo "##############################################################################"
-echo "## Configuring test environment"
-echo "##############################################################################"
-
-if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
- echo "Starting git daemon..."
- GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
- git init --bare "${GITDAEMON_DIR}/test.git"
- git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
- GITDAEMON_PID=$!
- disown $GITDAEMON_PID
-fi
-
-if [ -z "$SKIP_PROXY_TESTS" ]; then
- curl --location --silent --show-error https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar
-
- echo ""
- echo "Starting HTTP proxy (Basic)..."
- java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet &
-
- echo ""
- echo "Starting HTTP proxy (NTLM)..."
- java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
-fi
-
-if [ -z "$SKIP_NTLM_TESTS" ]; then
- curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.4.0/poxygit-0.4.0.jar >poxygit.jar
-
- echo ""
- echo "Starting HTTP server..."
- NTLM_DIR=`mktemp -d ${TMPDIR}/ntlm.XXXXXXXX`
- git init --bare "${NTLM_DIR}/test.git"
- java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${NTLM_DIR}" &
-fi
-
-if [ -z "$SKIP_SSH_TESTS" ]; then
- echo "Starting ssh daemon..."
- HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
- SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
- git init --bare "${SSHD_DIR}/test.git"
- cat >"${SSHD_DIR}/sshd_config" <<-EOF
- Port 2222
- ListenAddress 0.0.0.0
- Protocol 2
- HostKey ${SSHD_DIR}/id_rsa
- PidFile ${SSHD_DIR}/pid
- AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
- LogLevel DEBUG
- RSAAuthentication yes
- PasswordAuthentication yes
- PubkeyAuthentication yes
- ChallengeResponseAuthentication no
- StrictModes no
- # Required here as sshd will simply close connection otherwise
- UsePAM no
- EOF
- ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
- /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
-
- # Set up keys
- mkdir "${HOME}/.ssh"
- ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
- cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
- while read algorithm key comment; do
- echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
- done <"${SSHD_DIR}/id_rsa.pub"
-
- # Get the fingerprint for localhost and remove the colons so we can
- # parse it as a hex number. Older versions have a different output
- # format.
- if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
- SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
- else
- SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
- fi
-fi
-
-# Run the tests that do not require network connectivity.
-
-if [ -z "$SKIP_OFFLINE_TESTS" ]; then
- echo ""
- echo "##############################################################################"
- echo "## Running (offline) tests"
- echo "##############################################################################"
-
- run_test offline
-fi
-
-if [ -n "$RUN_INVASIVE_TESTS" ]; then
- echo ""
- echo "Running invasive tests"
- echo ""
-
- export GITTEST_INVASIVE_FS_SIZE=1
- export GITTEST_INVASIVE_MEMORY=1
- export GITTEST_INVASIVE_SPEED=1
- run_test invasive
- unset GITTEST_INVASIVE_FS_SIZE
- unset GITTEST_INVASIVE_MEMORY
- unset GITTEST_INVASIVE_SPEED
-fi
-
-if [ -z "$SKIP_ONLINE_TESTS" ]; then
- # Run the various online tests. The "online" test suite only includes the
- # default online tests that do not require additional configuration. The
- # "proxy" and "ssh" test suites require further setup.
-
- echo ""
- echo "##############################################################################"
- echo "## Running (online) tests"
- echo "##############################################################################"
-
- export GITTEST_FLAKY_RETRY=5
- run_test online
- unset GITTEST_FLAKY_RETRY
-fi
-
-if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
- echo ""
- echo "Running gitdaemon tests"
- echo ""
-
- export GITTEST_REMOTE_URL="git://localhost/test.git"
- run_test gitdaemon
- unset GITTEST_REMOTE_URL
-fi
-
-if [ -z "$SKIP_PROXY_TESTS" ]; then
- echo ""
- echo "Running proxy tests (Basic authentication)"
- echo ""
-
- export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
- export GITTEST_REMOTE_PROXY_USER="foo"
- export GITTEST_REMOTE_PROXY_PASS="bar"
- run_test proxy
- unset GITTEST_REMOTE_PROXY_HOST
- unset GITTEST_REMOTE_PROXY_USER
- unset GITTEST_REMOTE_PROXY_PASS
-
- echo ""
- echo "Running proxy tests (NTLM authentication)"
- echo ""
-
- export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
- export GITTEST_REMOTE_PROXY_USER="foo"
- export GITTEST_REMOTE_PROXY_PASS="bar"
- export GITTEST_FLAKY_RETRY=5
- run_test proxy
- unset GITTEST_FLAKY_RETRY
- unset GITTEST_REMOTE_PROXY_HOST
- unset GITTEST_REMOTE_PROXY_USER
- unset GITTEST_REMOTE_PROXY_PASS
-fi
-
-if [ -z "$SKIP_NTLM_TESTS" ]; then
- echo ""
- echo "Running NTLM tests (IIS emulation)"
- echo ""
-
- export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
- export GITTEST_REMOTE_USER="foo"
- export GITTEST_REMOTE_PASS="baz"
- run_test auth_clone_and_push
- unset GITTEST_REMOTE_URL
- unset GITTEST_REMOTE_USER
- unset GITTEST_REMOTE_PASS
-
- echo ""
- echo "Running NTLM tests (Apache emulation)"
- echo ""
-
- export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
- export GITTEST_REMOTE_USER="foo"
- export GITTEST_REMOTE_PASS="baz"
- run_test auth_clone_and_push
- unset GITTEST_REMOTE_URL
- unset GITTEST_REMOTE_USER
- unset GITTEST_REMOTE_PASS
-fi
-
-if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then
- echo ""
- echo "Running SPNEGO tests"
- echo ""
-
- if [ "$(uname -s)" = "Darwin" ]; then
- KINIT_FLAGS="--password-file=STDIN"
- fi
-
- echo $GITTEST_NEGOTIATE_PASSWORD | kinit $KINIT_FLAGS test@LIBGIT2.ORG
- klist -5f
-
- export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
- export GITTEST_REMOTE_DEFAULT="true"
- run_test auth_clone
- unset GITTEST_REMOTE_URL
- unset GITTEST_REMOTE_DEFAULT
-
- echo ""
- echo "Running SPNEGO tests (expect/continue)"
- echo ""
-
- export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
- export GITTEST_REMOTE_DEFAULT="true"
- export GITTEST_REMOTE_EXPECTCONTINUE="true"
- run_test auth_clone
- unset GITTEST_REMOTE_URL
- unset GITTEST_REMOTE_DEFAULT
- unset GITTEST_REMOTE_EXPECTCONTINUE
-
- kdestroy -A
-fi
-
-if [ -z "$SKIP_SSH_TESTS" ]; then
- echo ""
- echo "Running ssh tests"
- echo ""
-
- export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
- export GITTEST_REMOTE_USER=$USER
- export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
- export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
- export GITTEST_REMOTE_SSH_PASSPHRASE=""
- export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
- run_test ssh
- unset GITTEST_REMOTE_URL
- unset GITTEST_REMOTE_USER
- unset GITTEST_REMOTE_SSH_KEY
- unset GITTEST_REMOTE_SSH_PUBKEY
- unset GITTEST_REMOTE_SSH_PASSPHRASE
- unset GITTEST_REMOTE_SSH_FINGERPRINT
-fi
-
-if [ -z "$SKIP_FUZZERS" ]; then
- echo ""
- echo "##############################################################################"
- echo "## Running fuzzers"
- echo "##############################################################################"
-
- ctest -V -R 'fuzzer'
-fi
-
-cleanup
-
-if [ "$SUCCESS" -ne 1 ]; then
- echo "Some tests failed."
- exit 1
-fi
-
-echo "Success."
-exit 0
diff -Nru cargo-0.47.0/debian/libgit2/azure-pipelines.yml cargo-0.51.0/debian/libgit2/azure-pipelines.yml
--- cargo-0.47.0/debian/libgit2/azure-pipelines.yml 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/azure-pipelines.yml 1970-01-01 00:00:00.000000000 +0000
@@ -1,190 +0,0 @@
-resources:
-- repo: self
-
-trigger:
-- master
-- maint/*
-
-jobs:
-- job: linux_amd64_xenial_gcc_openssl
- displayName: 'Linux (amd64; Xenial; GCC; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: azure-pipelines/docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
- GITTEST_NEGOTIATE_PASSWORD=${{ variables.GITTEST_NEGOTIATE_PASSWORD }}
-
-- job: linux_amd64_xenial_gcc_mbedtls
- displayName: 'Linux (amd64; Xenial; GCC; mbedTLS)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: azure-pipelines/docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=gcc
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
- GITTEST_NEGOTIATE_PASSWORD=${{ variables.GITTEST_NEGOTIATE_PASSWORD }}
-
-- job: linux_amd64_xenial_clang_openssl
- displayName: 'Linux (amd64; Xenial; Clang; OpenSSL)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: azure-pipelines/docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=clang
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
- GITTEST_NEGOTIATE_PASSWORD=${{ variables.GITTEST_NEGOTIATE_PASSWORD }}
-
-- job: linux_amd64_xenial_clang_mbedtls
- displayName: 'Linux (amd64; Xenial; Clang; mbedTLS)'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - template: azure-pipelines/docker.yml
- parameters:
- docker:
- image: xenial
- base: ubuntu:xenial
- environmentVariables: |
- CC=clang
- CMAKE_GENERATOR=Ninja
- CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
- GITTEST_NEGOTIATE_PASSWORD=${{ variables.GITTEST_NEGOTIATE_PASSWORD }}
-
-- job: macos
- displayName: 'macOS (amd64; 10.15)'
- pool:
- vmImage: 'macOS-10.15'
- steps:
- - bash: . '$(Build.SourcesDirectory)/azure-pipelines/setup-osx.sh'
- displayName: Setup
- - template: azure-pipelines/bash.yml
- parameters:
- environmentVariables:
- TMPDIR: $(Agent.TempDirectory)
- PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
- CMAKE_GENERATOR: Ninja
- CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
- SKIP_SSH_TESTS: true
- GITTEST_NEGOTIATE_PASSWORD: ${{ variables.GITTEST_NEGOTIATE_PASSWORD }}
-
-- job: windows_vs_amd64
- displayName: 'Windows (amd64; Visual Studio)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - template: azure-pipelines/bash.yml
- parameters:
- environmentVariables:
- CMAKE_GENERATOR: Visual Studio 15 2017
- CMAKE_OPTIONS: -A x64 -DMSVC_CRTDBG=ON -DDEPRECATE_HARD=ON
- SKIP_SSH_TESTS: true
- SKIP_NEGOTIATE_TESTS: true
-
-- job: windows_vs_x86
- displayName: 'Windows (x86; Visual Studio)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - template: azure-pipelines/bash.yml
- parameters:
- environmentVariables:
- CMAKE_GENERATOR: Visual Studio 15 2017
- CMAKE_OPTIONS: -A Win32 -DMSVC_CRTDBG=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS
- SKIP_SSH_TESTS: true
- SKIP_NEGOTIATE_TESTS: true
-
-- job: windows_mingw_amd64
- displayName: 'Windows (amd64; MinGW)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - bash: . '$(Build.SourcesDirectory)\azure-pipelines\setup-mingw.sh'
- displayName: Setup
- env:
- TEMP: $(Agent.TempDirectory)
- ARCH: amd64
- - template: azure-pipelines/bash.yml
- parameters:
- environmentVariables:
- BUILD_PATH: $(Agent.TempDirectory)\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
- CMAKE_GENERATOR: MinGW Makefiles
- CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
- SKIP_SSH_TESTS: true
- SKIP_NEGOTIATE_TESTS: true
-
-- job: windows_mingw_x86
- displayName: 'Windows (x86; MinGW)'
- pool:
- vmImage: 'vs2017-win2016'
- steps:
- - bash: . '$(Build.SourcesDirectory)\azure-pipelines\setup-mingw.sh'
- displayName: Setup
- workingDirectory: '$(Build.BinariesDirectory)'
- env:
- TEMP: $(Agent.TempDirectory)
- ARCH: x86
- - template: azure-pipelines/bash.yml
- parameters:
- environmentVariables:
- BUILD_PATH: $(Agent.TempDirectory)\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
- CMAKE_GENERATOR: MinGW Makefiles
- CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
- SKIP_SSH_TESTS: true
- SKIP_NEGOTIATE_TESTS: true
-
-- job: documentation
- displayName: 'Generate Documentation'
- pool:
- vmImage: 'ubuntu-18.04'
- steps:
- - script: |
- cd $(Build.SourcesDirectory)/azure-pipelines/docker
- docker build -t libgit2/docurium --build-arg BASE=ubuntu:trusty -f docurium .
- displayName: 'Build Docker image'
- - script: |
- git config user.name 'Documentation Generation'
- git config user.email 'libgit2@users.noreply.github.com'
- git branch gh-pages origin/gh-pages
- docker run --rm -v $(Build.SourcesDirectory):/home/libgit2/source -w /home/libgit2/source libgit2/docurium:latest cm doc api.docurium
- git checkout gh-pages
- cp -R * '$(Build.BinariesDirectory)'
- displayName: 'Generate Documentation'
- - task: archivefiles@2
- displayName: 'Archive Documentation'
- inputs:
- rootFolderOrFile: '$(Build.BinariesDirectory)'
- includeRootFolder: false
- archiveFile: '$(Build.ArtifactStagingDirectory)/api-documentation.zip'
- - task: publishbuildartifacts@1
- displayName: 'Upload Documentation Artifact'
- inputs:
- pathToPublish: '$(Build.ArtifactStagingDirectory)'
- artifactName: 'docs'
- - script: |
- git remote -v
- echo 'machine github.com' > ~/.netrc
- echo 'login $(GITHUB_USERNAME)' >> ~/.netrc
- echo 'password $(GITHUB_PAT)' >> ~/.netrc
- git push origin gh-pages
- displayName: 'Publish Documentation'
- condition: and(eq(variables['Build.Repository.Name'], 'libgit2/libgit2'), eq(variables['Build.Reason'], 'IndividualCI'))
diff -Nru cargo-0.47.0/debian/libgit2/ci/build.sh cargo-0.51.0/debian/libgit2/ci/build.sh
--- cargo-0.47.0/debian/libgit2/ci/build.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/build.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Environment variables:
+#
+# SOURCE_DIR: Set to the directory of the libgit2 source (optional)
+# If not set, it will be derived relative to this script.
+
+set -e
+
+SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
+BUILD_DIR=$(pwd)
+BUILD_PATH=${BUILD_PATH:=$PATH}
+CMAKE=$(which cmake)
+CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
+
+if [[ "$(uname -s)" == MINGW* ]]; then
+ BUILD_PATH=$(cygpath "$BUILD_PATH")
+fi
+
+indent() { sed "s/^/ /"; }
+
+echo "Source directory: ${SOURCE_DIR}"
+echo "Build directory: ${BUILD_DIR}"
+echo ""
+
+if [ "$(uname -s)" = "Darwin" ]; then
+ echo "macOS version:"
+ sw_vers | indent
+fi
+
+if [ -f "/etc/debian_version" ]; then
+ echo "Debian version:"
+ (source /etc/lsb-release && echo "${DISTRIB_DESCRIPTION}") | indent
+fi
+
+echo "Kernel version:"
+uname -a 2>&1 | indent
+
+echo "CMake version:"
+env PATH="${BUILD_PATH}" "${CMAKE}" --version 2>&1 | indent
+
+if test -n "${CC}"; then
+ echo "Compiler version:"
+ "${CC}" --version 2>&1 | indent
+fi
+echo "Environment:"
+if test -n "${CC}"; then
+ echo "CC=${CC}" | indent
+fi
+if test -n "${CFLAGS}"; then
+ echo "CFLAGS=${CFLAGS}" | indent
+fi
+echo ""
+
+echo "##############################################################################"
+echo "## Configuring build environment"
+echo "##############################################################################"
+
+echo cmake -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
+env PATH="${BUILD_PATH}" "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS} -S "${SOURCE_DIR}"
+
+echo ""
+echo "##############################################################################"
+echo "## Building libgit2"
+echo "##############################################################################"
+
+env PATH="${BUILD_PATH}" "${CMAKE}" --build .
diff -Nru cargo-0.47.0/debian/libgit2/ci/coverity.sh cargo-0.51.0/debian/libgit2/ci/coverity.sh
--- cargo-0.47.0/debian/libgit2/ci/coverity.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/coverity.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,62 @@
+#!/bin/bash -e
+
+if test -z "$COVERITY_TOKEN"
+then
+ echo "Need to set a coverity token"
+ exit 1
+fi
+
+case $(uname -m) in
+ i?86)
+ BITS=32;;
+ amd64|x86_64)
+ BITS=64;;
+ *)
+ echo "Unsupported arch '$(uname -m)'"
+ exit 1;;
+esac
+
+SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS}
+SOURCE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)
+BUILD_DIR=${SOURCE_DIR}/coverity-build
+TOOL_DIR=${BUILD_DIR}/coverity-tools
+
+# Install coverity tools
+if ! test -d "$TOOL_DIR"
+then
+ mkdir -p "$TOOL_DIR"
+ curl --silent --show-error --location --data "project=libgit2&token=$COVERITY_TOKEN" "$SCAN_TOOL" |
+ tar -xzC "$TOOL_DIR"
+ ln -s "$(find "$TOOL_DIR" -type d -name 'cov-analysis*')" "$TOOL_DIR"/cov-analysis
+fi
+
+cp "${SOURCE_DIR}/script/user_nodefs.h" "$TOOL_DIR"/cov-analysis/config/
+
+# Build libgit2 with Coverity
+mkdir -p "$BUILD_DIR"
+cd "$BUILD_DIR"
+cmake "$SOURCE_DIR"
+COVERITY_UNSUPPORTED=1 \
+ "$TOOL_DIR/cov-analysis/bin/cov-build" --dir cov-int \
+ cmake --build .
+
+# Upload results
+tar -czf libgit2.tgz cov-int
+REVISION=$(cd ${SOURCE_DIR} && git rev-parse --short HEAD)
+HTML="$(curl \
+ --silent --show-error \
+ --write-out "\n%{http_code}" \
+ --form token="$COVERITY_TOKEN" \
+ --form email=libgit2@gmail.com \
+ --form file=@libgit2.tgz \
+ --form version="$REVISION" \
+ --form description="libgit2 build" \
+ https://scan.coverity.com/builds?project=libgit2)"
+
+# Status code is the last line
+STATUS_CODE="$(echo "$HTML" | tail -n1)"
+if test "${STATUS_CODE}" != 200 && test "${STATUS_CODE}" != 201
+then
+ echo "Received error code ${STATUS_CODE} from Coverity"
+ exit 1
+fi
diff -Nru cargo-0.47.0/debian/libgit2/ci/docker/bionic cargo-0.51.0/debian/libgit2/ci/docker/bionic
--- cargo-0.47.0/debian/libgit2/ci/docker/bionic 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/docker/bionic 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,44 @@
+ARG BASE=ubuntu:bionic
+FROM ${BASE} AS apt
+RUN apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+ clang \
+ cmake \
+ curl \
+ gcc \
+ git \
+ krb5-user \
+ libcurl4-openssl-dev \
+ libkrb5-dev \
+ libpcre3-dev \
+ libssh2-1-dev \
+ libssl-dev \
+ libz-dev \
+ ninja-build \
+ openjdk-8-jre-headless \
+ openssh-server \
+ openssl \
+ pkgconf \
+ python \
+ sudo \
+ valgrind \
+ && \
+ rm -rf /var/lib/apt/lists/*
+
+FROM apt AS mbedtls
+RUN cd /tmp && \
+ curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \
+ tar -xz && \
+ cd mbedtls-2.16.2 && \
+ scripts/config.pl set MBEDTLS_MD4_C 1 && \
+ CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
+ ninja install && \
+ cd .. && \
+ rm -rf mbedtls-2.16.2
+
+FROM mbedtls AS configure
+COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+RUN chmod a+x /usr/local/bin/entrypoint.sh
+RUN mkdir /var/run/sshd
+
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
diff -Nru cargo-0.47.0/debian/libgit2/ci/docker/docurium cargo-0.51.0/debian/libgit2/ci/docker/docurium
--- cargo-0.47.0/debian/libgit2/ci/docker/docurium 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/docker/docurium 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,4 @@
+ARG BASE=ubuntu:bionic
+FROM ${BASE}
+RUN apt update && apt install -y cmake pkg-config ruby ruby-dev llvm libclang-dev libssl-dev python-pygments
+RUN gem install docurium
diff -Nru cargo-0.47.0/debian/libgit2/ci/docker/entrypoint.sh cargo-0.51.0/debian/libgit2/ci/docker/entrypoint.sh
--- cargo-0.47.0/debian/libgit2/ci/docker/entrypoint.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/docker/entrypoint.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,4 @@
+#!/bin/bash -e
+useradd --shell /bin/bash libgit2
+chown --recursive libgit2:libgit2 /home/libgit2
+exec sudo --preserve-env --set-home --user=libgit2 "$@"
diff -Nru cargo-0.47.0/debian/libgit2/ci/docker/focal cargo-0.51.0/debian/libgit2/ci/docker/focal
--- cargo-0.47.0/debian/libgit2/ci/docker/focal 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/docker/focal 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,80 @@
+ARG BASE=ubuntu:focal
+FROM ${BASE} AS apt
+RUN apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+ bzip2 \
+ clang-10 \
+ cmake \
+ curl \
+ gcc-10 \
+ git \
+ krb5-user \
+ libcurl4-gnutls-dev \
+ libgcrypt20-dev \
+ libkrb5-dev \
+ libpcre3-dev \
+ libssl-dev \
+ libz-dev \
+ llvm-10 \
+ make \
+ ninja-build \
+ openjdk-8-jre-headless \
+ openssh-server \
+ openssl \
+ pkgconf \
+ python \
+ sudo \
+ valgrind \
+ && \
+ rm -rf /var/lib/apt/lists/* && \
+ mkdir /usr/local/msan
+
+FROM apt AS mbedtls
+RUN cd /tmp && \
+ curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \
+ tar -xz && \
+ cd mbedtls-2.16.2 && \
+ scripts/config.pl unset MBEDTLS_AESNI_C && \
+ scripts/config.pl set MBEDTLS_MD4_C 1 && \
+ mkdir build build-msan && \
+ cd build && \
+ CC=clang-10 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+ ninja install && \
+ cd ../build-msan && \
+ CC=clang-10 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=MemSanDbg -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
+ ninja install && \
+ cd .. && \
+ rm -rf mbedtls-2.16.2
+
+FROM mbedtls AS libssh2
+RUN cd /tmp && \
+ curl --insecure --location --silent --show-error https://www.libssh2.org/download/libssh2-1.8.2.tar.gz | \
+ tar -xz && \
+ cd libssh2-1.8.2 && \
+ mkdir build build-msan && \
+ cd build && \
+ CC=clang-10 CFLAGS="-fPIC" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=Libgcrypt -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
+ ninja install && \
+ cd ../build-msan && \
+ CC=clang-10 CFLAGS="-fPIC -fsanitize=memory -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=memory" cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=mbedTLS -DCMAKE_PREFIX_PATH=/usr/local/msan -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
+ ninja install && \
+ cd .. && \
+ rm -rf libssh2-1.8.2
+
+FROM libssh2 AS valgrind
+RUN cd /tmp && \
+ curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2 | \
+ tar -xj && \
+ cd valgrind-3.15.0 && \
+ CC=clang-10 ./configure && \
+ make MAKEFLAGS="-j -l$(grep -c ^processor /proc/cpuinfo)" && \
+ make install && \
+ cd .. && \
+ rm -rf valgrind-3.15.0
+
+FROM valgrind AS configure
+COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+RUN chmod a+x /usr/local/bin/entrypoint.sh
+RUN mkdir /var/run/sshd
+
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
diff -Nru cargo-0.47.0/debian/libgit2/ci/docker/xenial cargo-0.51.0/debian/libgit2/ci/docker/xenial
--- cargo-0.47.0/debian/libgit2/ci/docker/xenial 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/docker/xenial 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,67 @@
+ARG BASE=ubuntu:xenial
+FROM ${BASE} AS apt
+RUN apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
+ bzip2 \
+ clang \
+ cmake \
+ curl \
+ gcc \
+ git \
+ krb5-user \
+ libcurl4-gnutls-dev \
+ libgcrypt20-dev \
+ libkrb5-dev \
+ libpcre3-dev \
+ libssl-dev \
+ libz-dev \
+ make \
+ ninja-build \
+ openjdk-8-jre-headless \
+ openssh-server \
+ openssl \
+ pkgconf \
+ python \
+ sudo \
+ valgrind \
+ && \
+ rm -rf /var/lib/apt/lists/*
+
+FROM apt AS mbedtls
+RUN cd /tmp && \
+ curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \
+ tar -xz && \
+ cd mbedtls-2.16.2 && \
+ scripts/config.pl set MBEDTLS_MD4_C 1 && \
+ CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
+ ninja install && \
+ cd .. && \
+ rm -rf mbedtls-2.16.2
+
+FROM mbedtls AS libssh2
+RUN cd /tmp && \
+ curl --insecure --location --silent --show-error https://www.libssh2.org/download/libssh2-1.8.2.tar.gz | \
+ tar -xz && \
+ cd libssh2-1.8.2 && \
+ CFLAGS=-fPIC cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCRYPTO_BACKEND=Libgcrypt . && \
+ ninja install && \
+ cd .. && \
+ rm -rf libssh2-1.8.2
+
+FROM libssh2 AS valgrind
+RUN cd /tmp && \
+ curl --insecure --location --silent --show-error https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2 | \
+ tar -xj && \
+ cd valgrind-3.15.0 && \
+ ./configure && \
+ make && \
+ make install && \
+ cd .. && \
+ rm -rf valgrind-3.15.0
+
+FROM valgrind AS configure
+COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+RUN chmod a+x /usr/local/bin/entrypoint.sh
+RUN mkdir /var/run/sshd
+
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
diff -Nru cargo-0.47.0/debian/libgit2/ci/getcontainer.sh cargo-0.51.0/debian/libgit2/ci/getcontainer.sh
--- cargo-0.47.0/debian/libgit2/ci/getcontainer.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/getcontainer.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -e
+
+IMAGE_NAME=$1
+DOCKERFILE_PATH=$2
+
+if [ "${IMAGE_NAME}" = "" ]; then
+ echo "usage: $0 image_name [dockerfile]"
+ exit 1
+fi
+
+if [ "${DOCKERFILE_PATH}" = "" ]; then
+ DOCKERFILE_PATH="${IMAGE_NAME}"
+fi
+
+if [ "${DOCKER_REGISTRY}" = "" ]; then
+ echo "DOCKER_REGISTRY environment variable is unset."
+ echo "Not running inside GitHub Actions or misconfigured?"
+ exit 1
+fi
+
+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
+DOCKER_SHA=$(git log -1 --pretty=format:"%h" -- "${DOCKERFILE_PATH}")
+echo "docker-sha=${DOCKER_SHA}" >> $GITHUB_ENV
+
+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
+
+exists="true"
+docker login https://${DOCKER_REGISTRY} -u ${GITHUB_ACTOR} -p ${GITHUB_TOKEN} || exists="false"
+
+if [ "${exists}" != "false" ]; then
+ docker pull ${DOCKER_REGISTRY_CONTAINER_SHA} || exists="false"
+fi
+
+if [ "${exists}" = "true" ]; then
+ echo "docker-container-exists=true" >> $GITHUB_ENV
+else
+ echo "docker-container-exists=false" >> $GITHUB_ENV
+fi
diff -Nru cargo-0.47.0/debian/libgit2/ci/setup-mingw.sh cargo-0.51.0/debian/libgit2/ci/setup-mingw.sh
--- cargo-0.47.0/debian/libgit2/ci/setup-mingw.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/setup-mingw.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,25 @@
+#!/bin/sh -e
+
+echo "##############################################################################"
+echo "## Downloading mingw"
+echo "##############################################################################"
+
+BUILD_TEMP=${BUILD_TEMP:=$TEMP}
+BUILD_TEMP=$(cygpath $BUILD_TEMP)
+
+case "$ARCH" in
+ amd64)
+ MINGW_URI="https://bintray.com/libgit2/build-dependencies/download_file?file_path=mingw-w64-x86_64-8.1.0-release-win32-seh-rt_v6-rev0.zip";;
+ x86)
+ MINGW_URI="https://bintray.com/libgit2/build-dependencies/download_file?file_path=mingw-w64-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";;
+esac
+
+if [ -z "$MINGW_URI" ]; then
+ echo "No URL"
+ exit 1
+fi
+
+mkdir -p "$BUILD_TEMP"
+
+curl -s -L "$MINGW_URI" -o "$BUILD_TEMP"/mingw-"$ARCH".zip
+unzip -q "$BUILD_TEMP"/mingw-"$ARCH".zip -d "$BUILD_TEMP"
diff -Nru cargo-0.47.0/debian/libgit2/ci/setup-osx.sh cargo-0.51.0/debian/libgit2/ci/setup-osx.sh
--- cargo-0.47.0/debian/libgit2/ci/setup-osx.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/setup-osx.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -x
+
+brew update
+brew install pkgconfig zlib curl openssl libssh2 ninja
+
+ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib /usr/local/lib
diff -Nru cargo-0.47.0/debian/libgit2/ci/test.sh cargo-0.51.0/debian/libgit2/ci/test.sh
--- cargo-0.47.0/debian/libgit2/ci/test.sh 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/ci/test.sh 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,325 @@
+#!/usr/bin/env bash
+
+set -e
+
+if [ -n "$SKIP_TESTS" ]; then
+ exit 0
+fi
+
+# Windows doesn't run the NTLM tests properly (yet)
+if [[ "$(uname -s)" == MINGW* ]]; then
+ SKIP_NTLM_TESTS=1
+fi
+
+SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
+BUILD_DIR=$(pwd)
+TMPDIR=${TMPDIR:-/tmp}
+USER=${USER:-$(whoami)}
+
+SUCCESS=1
+
+cleanup() {
+ echo "Cleaning up..."
+
+ if [ ! -z "$GITDAEMON_PID" ]; then
+ echo "Stopping git daemon..."
+ kill $GITDAEMON_PID
+ fi
+
+ if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
+ echo "Stopping SSH..."
+ kill $(cat "${SSHD_DIR}/pid")
+ fi
+
+ echo "Done."
+}
+
+run_test() {
+ if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
+ ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
+ else
+ ATTEMPTS_REMAIN=1
+ fi
+
+ FAILED=0
+ while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
+ if [ "$FAILED" -eq 1 ]; then
+ echo ""
+ echo "Re-running flaky ${1} tests..."
+ echo ""
+ fi
+
+ RETURN_CODE=0
+
+ CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
+
+ if [ "$RETURN_CODE" -eq 0 ]; then
+ FAILED=0
+ break
+ fi
+
+ echo "Test exited with code: $RETURN_CODE"
+ ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
+ FAILED=1
+ done
+
+ if [ "$FAILED" -ne 0 ]; then
+ SUCCESS=0
+ fi
+}
+
+# Configure the test environment; run them early so that we're certain
+# that they're started by the time we need them.
+
+echo "##############################################################################"
+echo "## Configuring test environment"
+echo "##############################################################################"
+
+if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
+ echo "Starting git daemon..."
+ GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
+ git init --bare "${GITDAEMON_DIR}/test.git"
+ git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
+ GITDAEMON_PID=$!
+ disown $GITDAEMON_PID
+fi
+
+if [ -z "$SKIP_PROXY_TESTS" ]; then
+ curl --location --silent --show-error https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar
+
+ echo ""
+ echo "Starting HTTP proxy (Basic)..."
+ java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet &
+
+ echo ""
+ echo "Starting HTTP proxy (NTLM)..."
+ java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
+fi
+
+if [ -z "$SKIP_NTLM_TESTS" ]; then
+ curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.4.0/poxygit-0.4.0.jar >poxygit.jar
+
+ echo ""
+ echo "Starting HTTP server..."
+ NTLM_DIR=`mktemp -d ${TMPDIR}/ntlm.XXXXXXXX`
+ git init --bare "${NTLM_DIR}/test.git"
+ java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${NTLM_DIR}" &
+fi
+
+if [ -z "$SKIP_SSH_TESTS" ]; then
+ echo "Starting ssh daemon..."
+ HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
+ SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
+ git init --bare "${SSHD_DIR}/test.git"
+ cat >"${SSHD_DIR}/sshd_config" <<-EOF
+ Port 2222
+ ListenAddress 0.0.0.0
+ Protocol 2
+ HostKey ${SSHD_DIR}/id_rsa
+ PidFile ${SSHD_DIR}/pid
+ AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
+ LogLevel DEBUG
+ RSAAuthentication yes
+ PasswordAuthentication yes
+ PubkeyAuthentication yes
+ ChallengeResponseAuthentication no
+ StrictModes no
+ # Required here as sshd will simply close connection otherwise
+ UsePAM no
+ EOF
+ ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
+ /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
+
+ # Set up keys
+ mkdir "${HOME}/.ssh"
+ ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
+ cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
+ while read algorithm key comment; do
+ echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
+ done <"${SSHD_DIR}/id_rsa.pub"
+
+ # Get the fingerprint for localhost and remove the colons so we can
+ # parse it as a hex number. Older versions have a different output
+ # format.
+ if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
+ SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
+ else
+ SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
+ fi
+fi
+
+# Run the tests that do not require network connectivity.
+
+if [ -z "$SKIP_OFFLINE_TESTS" ]; then
+ echo ""
+ echo "##############################################################################"
+ echo "## Running (offline) tests"
+ echo "##############################################################################"
+
+ run_test offline
+fi
+
+if [ -n "$RUN_INVASIVE_TESTS" ]; then
+ echo ""
+ echo "Running invasive tests"
+ echo ""
+
+ export GITTEST_INVASIVE_FS_SIZE=1
+ export GITTEST_INVASIVE_MEMORY=1
+ export GITTEST_INVASIVE_SPEED=1
+ run_test invasive
+ unset GITTEST_INVASIVE_FS_SIZE
+ unset GITTEST_INVASIVE_MEMORY
+ unset GITTEST_INVASIVE_SPEED
+fi
+
+if [ -z "$SKIP_ONLINE_TESTS" ]; then
+ # Run the various online tests. The "online" test suite only includes the
+ # default online tests that do not require additional configuration. The
+ # "proxy" and "ssh" test suites require further setup.
+
+ echo ""
+ echo "##############################################################################"
+ echo "## Running (online) tests"
+ echo "##############################################################################"
+
+ export GITTEST_FLAKY_RETRY=5
+ run_test online
+ unset GITTEST_FLAKY_RETRY
+fi
+
+if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
+ echo ""
+ echo "Running gitdaemon tests"
+ echo ""
+
+ export GITTEST_REMOTE_URL="git://localhost/test.git"
+ run_test gitdaemon
+ unset GITTEST_REMOTE_URL
+fi
+
+if [ -z "$SKIP_PROXY_TESTS" ]; then
+ echo ""
+ echo "Running proxy tests (Basic authentication)"
+ echo ""
+
+ export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
+ export GITTEST_REMOTE_PROXY_USER="foo"
+ export GITTEST_REMOTE_PROXY_PASS="bar"
+ run_test proxy
+ unset GITTEST_REMOTE_PROXY_HOST
+ unset GITTEST_REMOTE_PROXY_USER
+ unset GITTEST_REMOTE_PROXY_PASS
+
+ echo ""
+ echo "Running proxy tests (NTLM authentication)"
+ echo ""
+
+ export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
+ export GITTEST_REMOTE_PROXY_USER="foo"
+ export GITTEST_REMOTE_PROXY_PASS="bar"
+ export GITTEST_FLAKY_RETRY=5
+ run_test proxy
+ unset GITTEST_FLAKY_RETRY
+ unset GITTEST_REMOTE_PROXY_HOST
+ unset GITTEST_REMOTE_PROXY_USER
+ unset GITTEST_REMOTE_PROXY_PASS
+fi
+
+if [ -z "$SKIP_NTLM_TESTS" ]; then
+ echo ""
+ echo "Running NTLM tests (IIS emulation)"
+ echo ""
+
+ export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
+ export GITTEST_REMOTE_USER="foo"
+ export GITTEST_REMOTE_PASS="baz"
+ run_test auth_clone_and_push
+ unset GITTEST_REMOTE_URL
+ unset GITTEST_REMOTE_USER
+ unset GITTEST_REMOTE_PASS
+
+ echo ""
+ echo "Running NTLM tests (Apache emulation)"
+ echo ""
+
+ export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
+ export GITTEST_REMOTE_USER="foo"
+ export GITTEST_REMOTE_PASS="baz"
+ run_test auth_clone_and_push
+ unset GITTEST_REMOTE_URL
+ unset GITTEST_REMOTE_USER
+ unset GITTEST_REMOTE_PASS
+fi
+
+if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then
+ echo ""
+ echo "Running SPNEGO tests"
+ echo ""
+
+ if [ "$(uname -s)" = "Darwin" ]; then
+ KINIT_FLAGS="--password-file=STDIN"
+ fi
+
+ echo $GITTEST_NEGOTIATE_PASSWORD | kinit $KINIT_FLAGS test@LIBGIT2.ORG
+ klist -5f
+
+ export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
+ export GITTEST_REMOTE_DEFAULT="true"
+ run_test auth_clone
+ unset GITTEST_REMOTE_URL
+ unset GITTEST_REMOTE_DEFAULT
+
+ echo ""
+ echo "Running SPNEGO tests (expect/continue)"
+ echo ""
+
+ export GITTEST_REMOTE_URL="https://test.libgit2.org/kerberos/empty.git"
+ export GITTEST_REMOTE_DEFAULT="true"
+ export GITTEST_REMOTE_EXPECTCONTINUE="true"
+ run_test auth_clone
+ unset GITTEST_REMOTE_URL
+ unset GITTEST_REMOTE_DEFAULT
+ unset GITTEST_REMOTE_EXPECTCONTINUE
+
+ kdestroy -A
+fi
+
+if [ -z "$SKIP_SSH_TESTS" ]; then
+ echo ""
+ echo "Running ssh tests"
+ echo ""
+
+ export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
+ export GITTEST_REMOTE_USER=$USER
+ export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
+ export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
+ export GITTEST_REMOTE_SSH_PASSPHRASE=""
+ export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
+ run_test ssh
+ unset GITTEST_REMOTE_URL
+ unset GITTEST_REMOTE_USER
+ unset GITTEST_REMOTE_SSH_KEY
+ unset GITTEST_REMOTE_SSH_PUBKEY
+ unset GITTEST_REMOTE_SSH_PASSPHRASE
+ unset GITTEST_REMOTE_SSH_FINGERPRINT
+fi
+
+if [ -z "$SKIP_FUZZERS" ]; then
+ echo ""
+ echo "##############################################################################"
+ echo "## Running fuzzers"
+ echo "##############################################################################"
+
+ ctest -V -R 'fuzzer'
+fi
+
+cleanup
+
+if [ "$SUCCESS" -ne 1 ]; then
+ echo "Some tests failed."
+ exit 1
+fi
+
+echo "Success."
+exit 0
diff -Nru cargo-0.47.0/debian/libgit2/cmake/AddCFlagIfSupported.cmake cargo-0.51.0/debian/libgit2/cmake/AddCFlagIfSupported.cmake
--- cargo-0.47.0/debian/libgit2/cmake/AddCFlagIfSupported.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/AddCFlagIfSupported.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,30 @@
+# - 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 -Nru cargo-0.47.0/debian/libgit2/cmake/EnableWarnings.cmake cargo-0.51.0/debian/libgit2/cmake/EnableWarnings.cmake
--- cargo-0.47.0/debian/libgit2/cmake/EnableWarnings.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/EnableWarnings.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,15 @@
+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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindCoreFoundation.cmake cargo-0.51.0/debian/libgit2/cmake/FindCoreFoundation.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindCoreFoundation.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindCoreFoundation.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,26 @@
+# 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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindGSSAPI.cmake cargo-0.51.0/debian/libgit2/cmake/FindGSSAPI.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindGSSAPI.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindGSSAPI.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,324 @@
+# - 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 TURE 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 (PKG_CONFIG_FOUND)
+
+ 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 (UNIX)
+
+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 (GSSAPI_LIBRARY)
+
+ if (KRB5_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${KRB5_LIBRARY}
+ )
+ endif (KRB5_LIBRARY)
+
+ if (K5CRYPTO_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${K5CRYPTO_LIBRARY}
+ )
+ endif (K5CRYPTO_LIBRARY)
+
+ if (COM_ERR_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${COM_ERR_LIBRARY}
+ )
+ endif (COM_ERR_LIBRARY)
+endif (GSSAPI_FLAVOR_MIT)
+
+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 (GSSAPI_LIBRARY)
+
+ if (KRB5_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${KRB5_LIBRARY}
+ )
+ endif (KRB5_LIBRARY)
+
+ if (HCRYPTO_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${HCRYPTO_LIBRARY}
+ )
+ endif (HCRYPTO_LIBRARY)
+
+ if (COM_ERR_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${COM_ERR_LIBRARY}
+ )
+ endif (COM_ERR_LIBRARY)
+
+ if (HEIMNTLM_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${HEIMNTLM_LIBRARY}
+ )
+ endif (HEIMNTLM_LIBRARY)
+
+ if (HX509_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${HX509_LIBRARY}
+ )
+ endif (HX509_LIBRARY)
+
+ if (ASN1_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${ASN1_LIBRARY}
+ )
+ endif (ASN1_LIBRARY)
+
+ if (WIND_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${WIND_LIBRARY}
+ )
+ endif (WIND_LIBRARY)
+
+ if (ROKEN_LIBRARY)
+ set(GSSAPI_LIBRARIES
+ ${GSSAPI_LIBRARIES}
+ ${WIND_LIBRARY}
+ )
+ endif (ROKEN_LIBRARY)
+endif (GSSAPI_FLAVOR_HEIMDAL)
+
+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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindGSSFramework.cmake cargo-0.51.0/debian/libgit2/cmake/FindGSSFramework.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindGSSFramework.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindGSSFramework.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,28 @@
+# 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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindHTTP_Parser.cmake cargo-0.51.0/debian/libgit2/cmake/FindHTTP_Parser.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindHTTP_Parser.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindHTTP_Parser.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,39 @@
+# - 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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindIconv.cmake cargo-0.51.0/debian/libgit2/cmake/FindIconv.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindIconv.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindIconv.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,45 @@
+# - 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)
+
+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(NOT ICONV_FIND_QUIETLY)
+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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindmbedTLS.cmake cargo-0.51.0/debian/libgit2/cmake/FindmbedTLS.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindmbedTLS.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindmbedTLS.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,93 @@
+# - 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(MBEDTLSMATCH)
+ MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
+ MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
+ MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
+ ENDIF(NOT MBEDTLS_FIND_QUIETLY)
+ELSE(MBEDTLS_FOUND)
+ IF(MBEDTLS_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find mbedTLS")
+ ENDIF(MBEDTLS_FIND_REQUIRED)
+ENDIF(MBEDTLS_FOUND)
+
+MARK_AS_ADVANCED(
+ MBEDTLS_INCLUDE_DIR
+ MBEDTLS_LIBRARY_DIR
+ MBEDTLS_LIBRARIES
+ MBEDTLS_LIBRARY
+ MBEDX509_LIBRARY
+ MBEDCRYPTO_LIBRARY
+)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/FindPCRE2.cmake cargo-0.51.0/debian/libgit2/cmake/FindPCRE2.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindPCRE2.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindPCRE2.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,37 @@
+# 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 pcre2posix.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(PCRE2_FOUND)
+
+MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/FindPCRE.cmake cargo-0.51.0/debian/libgit2/cmake/FindPCRE.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindPCRE.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindPCRE.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,38 @@
+# 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 pcreposix.h)
+
+# Look for the library.
+FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)
+FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix)
+
+# 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_POSIX_LIBRARY PCRE_INCLUDE_DIR)
+
+# Copy the results to the output variables.
+IF(PCRE_FOUND)
+ SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
+ SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
+ELSE(PCRE_FOUND)
+ SET(PCRE_LIBRARIES)
+ SET(PCRE_INCLUDE_DIRS)
+ENDIF(PCRE_FOUND)
+
+MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/FindPkgLibraries.cmake cargo-0.51.0/debian/libgit2/cmake/FindPkgLibraries.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindPkgLibraries.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindPkgLibraries.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,28 @@
+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(LIBRARY)
+
+ 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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindSecurity.cmake cargo-0.51.0/debian/libgit2/cmake/FindSecurity.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindSecurity.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindSecurity.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,28 @@
+# 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 -Nru cargo-0.47.0/debian/libgit2/cmake/FindStatNsec.cmake cargo-0.51.0/debian/libgit2/cmake/FindStatNsec.cmake
--- cargo-0.47.0/debian/libgit2/cmake/FindStatNsec.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/FindStatNsec.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,26 @@
+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()
+
+IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
+ OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
+ELSE()
+ SET(USE_NSEC OFF)
+ENDIF()
+
+ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
diff -Nru cargo-0.47.0/debian/libgit2/cmake/IdeSplitSources.cmake cargo-0.51.0/debian/libgit2/cmake/IdeSplitSources.cmake
--- cargo-0.47.0/debian/libgit2/cmake/IdeSplitSources.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/IdeSplitSources.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,22 @@
+# 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_clar 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 ${libgit2_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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/AddCFlagIfSupported.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/AddCFlagIfSupported.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/AddCFlagIfSupported.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/AddCFlagIfSupported.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in cargo-0.51.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in
--- cargo-0.47.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in 1970-01-01 00:00:00.000000000 +0000
@@ -1,29 +0,0 @@
-@CHECK_PROTOTYPE_DEFINITION_HEADER@
-
-static void cmakeRequireSymbol(int dummy, ...) {
- (void) dummy;
-}
-
-static void checkSymbol(void) {
-#ifndef @CHECK_PROTOTYPE_DEFINITION_SYMBOL@
- cmakeRequireSymbol(0, &@CHECK_PROTOTYPE_DEFINITION_SYMBOL@);
-#endif
-}
-
-@CHECK_PROTOTYPE_DEFINITION_PROTO@ {
- return @CHECK_PROTOTYPE_DEFINITION_RETURN@;
-}
-
-#ifdef __CLASSIC_C__
-int main() {
- int ac;
- char*av[];
-#else
-int main(int ac, char *av[]) {
-#endif
- checkSymbol();
- if (ac > 1000) {
- return *av[0];
- }
- return 0;
-}
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,96 +0,0 @@
-# - Check if the protoype we expect is correct.
-# check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)
-# FUNCTION - The name of the function (used to check if prototype exists)
-# PROTOTYPE- The prototype to check.
-# RETURN - The return value of the function.
-# HEADER - The header files required.
-# VARIABLE - The variable to store the result.
-# Example:
-# check_prototype_definition(getpwent_r
-# "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
-# "NULL"
-# "unistd.h;pwd.h"
-# SOLARIS_GETPWENT_R)
-# The following variables may be set before calling this macro to
-# modify the way the check is run:
-#
-# CMAKE_REQUIRED_FLAGS = string of compile command line flags
-# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
-# CMAKE_REQUIRED_INCLUDES = list of include directories
-# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
-
-#=============================================================================
-# Copyright 2005-2009 Kitware, Inc.
-# Copyright 2010-2011 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.
-#=============================================================================
-# (To distribute this file outside of CMake, substitute the full
-# License text for the above reference.)
-#
-
-get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
-
-function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
-
- if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
- set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n")
-
- set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS})
- if (CMAKE_REQUIRED_LIBRARIES)
- set(CHECK_PROTOTYPE_DEFINITION_LIBS
- "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
- else(CMAKE_REQUIRED_LIBRARIES)
- set(CHECK_PROTOTYPE_DEFINITION_LIBS)
- endif(CMAKE_REQUIRED_LIBRARIES)
- if (CMAKE_REQUIRED_INCLUDES)
- set(CMAKE_SYMBOL_EXISTS_INCLUDES
- "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
- else(CMAKE_REQUIRED_INCLUDES)
- set(CMAKE_SYMBOL_EXISTS_INCLUDES)
- endif(CMAKE_REQUIRED_INCLUDES)
-
- foreach(_FILE ${_HEADER})
- set(CHECK_PROTOTYPE_DEFINITION_HEADER
- "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n")
- endforeach(_FILE)
-
- set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION})
- set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE})
- set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN})
-
- configure_file("${__check_proto_def_dir}/CheckPrototypeDefinition.c.in"
- "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
-
- file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE)
-
- try_compile(${_VARIABLE}
- ${CMAKE_BINARY_DIR}
- ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
- COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
- CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
- "${CHECK_PROTOTYPE_DEFINITION_LIBS}"
- "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
- OUTPUT_VARIABLE OUTPUT)
-
- if (${_VARIABLE})
- set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
- message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
- "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n"
- "${OUTPUT}\n\n")
- else (${_VARIABLE})
- message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False")
- set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n"
- "${OUTPUT}\n\n${_SOURCE}\n\n")
- endif (${_VARIABLE})
- endif("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
-
-endfunction(CHECK_PROTOTYPE_DEFINITION)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/EnableWarnings.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/EnableWarnings.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/EnableWarnings.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/EnableWarnings.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindCoreFoundation.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindCoreFoundation.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindCoreFoundation.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindCoreFoundation.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindGSSAPI.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindGSSAPI.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindGSSAPI.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindGSSAPI.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,324 +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 TURE 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 (PKG_CONFIG_FOUND)
-
- 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 (UNIX)
-
-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 (GSSAPI_LIBRARY)
-
- if (KRB5_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${KRB5_LIBRARY}
- )
- endif (KRB5_LIBRARY)
-
- if (K5CRYPTO_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${K5CRYPTO_LIBRARY}
- )
- endif (K5CRYPTO_LIBRARY)
-
- if (COM_ERR_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${COM_ERR_LIBRARY}
- )
- endif (COM_ERR_LIBRARY)
-endif (GSSAPI_FLAVOR_MIT)
-
-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 (GSSAPI_LIBRARY)
-
- if (KRB5_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${KRB5_LIBRARY}
- )
- endif (KRB5_LIBRARY)
-
- if (HCRYPTO_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${HCRYPTO_LIBRARY}
- )
- endif (HCRYPTO_LIBRARY)
-
- if (COM_ERR_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${COM_ERR_LIBRARY}
- )
- endif (COM_ERR_LIBRARY)
-
- if (HEIMNTLM_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${HEIMNTLM_LIBRARY}
- )
- endif (HEIMNTLM_LIBRARY)
-
- if (HX509_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${HX509_LIBRARY}
- )
- endif (HX509_LIBRARY)
-
- if (ASN1_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${ASN1_LIBRARY}
- )
- endif (ASN1_LIBRARY)
-
- if (WIND_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${WIND_LIBRARY}
- )
- endif (WIND_LIBRARY)
-
- if (ROKEN_LIBRARY)
- set(GSSAPI_LIBRARIES
- ${GSSAPI_LIBRARIES}
- ${WIND_LIBRARY}
- )
- endif (ROKEN_LIBRARY)
-endif (GSSAPI_FLAVOR_HEIMDAL)
-
-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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindGSSFramework.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindGSSFramework.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindGSSFramework.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindGSSFramework.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindHTTP_Parser.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindHTTP_Parser.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindHTTP_Parser.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindHTTP_Parser.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindIconv.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindIconv.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindIconv.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindIconv.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,45 +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)
-
-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(NOT ICONV_FIND_QUIETLY)
-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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindmbedTLS.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindmbedTLS.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindmbedTLS.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindmbedTLS.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,93 +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(MBEDTLSMATCH)
- MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
- MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
- MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
- ENDIF(NOT MBEDTLS_FIND_QUIETLY)
-ELSE(MBEDTLS_FOUND)
- IF(MBEDTLS_FIND_REQUIRED)
- MESSAGE(FATAL_ERROR "Could not find mbedTLS")
- ENDIF(MBEDTLS_FIND_REQUIRED)
-ENDIF(MBEDTLS_FOUND)
-
-MARK_AS_ADVANCED(
- MBEDTLS_INCLUDE_DIR
- MBEDTLS_LIBRARY_DIR
- MBEDTLS_LIBRARIES
- MBEDTLS_LIBRARY
- MBEDX509_LIBRARY
- MBEDCRYPTO_LIBRARY
-)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindPCRE2.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindPCRE2.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindPCRE2.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindPCRE2.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 pcre2posix.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(PCRE2_FOUND)
-
-MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindPCRE.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindPCRE.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindPCRE.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindPCRE.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,38 +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 pcreposix.h)
-
-# Look for the library.
-FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)
-FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix)
-
-# 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_POSIX_LIBRARY PCRE_INCLUDE_DIR)
-
-# Copy the results to the output variables.
-IF(PCRE_FOUND)
- SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
- SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
-ELSE(PCRE_FOUND)
- SET(PCRE_LIBRARIES)
- SET(PCRE_INCLUDE_DIRS)
-ENDIF(PCRE_FOUND)
-
-MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindPkgLibraries.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindPkgLibraries.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindPkgLibraries.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindPkgLibraries.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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(LIBRARY)
-
- 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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindSecurity.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindSecurity.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindSecurity.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindSecurity.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/FindStatNsec.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/FindStatNsec.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/FindStatNsec.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/FindStatNsec.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,26 +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()
-
-IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
- OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
-ELSE()
- SET(USE_NSEC OFF)
-ENDIF()
-
-ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/IdeSplitSources.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/IdeSplitSources.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/IdeSplitSources.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/IdeSplitSources.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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_clar 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 ${libgit2_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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/PkgBuildConfig.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/PkgBuildConfig.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/PkgBuildConfig.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/PkgBuildConfig.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/SanitizeBool.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/SanitizeBool.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/SanitizeBool.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/SanitizeBool.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -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 -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/SelectGSSAPI.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/SelectGSSAPI.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/SelectGSSAPI.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/SelectGSSAPI.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,56 +0,0 @@
-# Select the backend to use
-
-# We try to find any packages our backends might use
-
-INCLUDE(SanitizeBool)
-
-FIND_PACKAGE(GSSAPI)
-IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
- INCLUDE(FindGSSFramework)
-ENDIF()
-
-# Auto-select GSS backend
-SanitizeBool(USE_GSSAPI)
-IF (USE_GSSAPI STREQUAL ON)
- IF (GSSFRAMEWORK_FOUND)
- SET(GSS_BACKEND "GSS.framework")
- ELSEIF(GSSAPI_FOUND)
- SET(GSS_BACKEND "gssapi")
- ELSE()
- MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend."
- "Please pass the backend name explicitly (-DUSE_GSS=backend)")
- ENDIF()
-ELSEIF(USE_GSSAPI)
- # Backend was explicitly set
- SET(GSS_BACKEND ${USE_GSSAPI})
-ELSE()
- SET(GSS_BACKEND NO)
-ENDIF()
-
-IF(GSS_BACKEND)
- # Check that we can find what's required for the selected backend
- IF (GSS_BACKEND STREQUAL "GSS.framework")
- IF (NOT GSSFRAMEWORK_FOUND)
- MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
- ENDIF()
-
- LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES})
-
- SET(GIT_GSSFRAMEWORK 1)
- ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${GSS_BACKEND})")
- ELSEIF (GSS_BACKEND STREQUAL "gssapi")
- IF (NOT GSSAPI_FOUND)
- MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
- ENDIF()
-
- LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES})
-
- SET(GIT_GSSAPI 1)
- ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${GSS_BACKEND})")
- ELSE()
- MESSAGE(FATAL_ERROR "Asked for backend ${GSS_BACKEND} but it wasn't found")
- ENDIF()
-ELSE()
- SET(GIT_GSSAPI 0)
- ADD_FEATURE_INFO(SPNEGO NO "SPNEGO authentication support")
-ENDIF()
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/SelectHashes.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/SelectHashes.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/SelectHashes.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/SelectHashes.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,69 +0,0 @@
-# Select a hash backend
-
-INCLUDE(SanitizeBool)
-
-# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
-
-SanitizeBool(USE_SHA1)
-IF(USE_SHA1 STREQUAL ON OR USE_SHA1 STREQUAL "CollisionDetection")
- SET(SHA1_BACKEND "CollisionDetection")
-ELSEIF(USE_SHA1 STREQUAL "HTTPS")
- message(STATUS "Checking HTTPS backend… ${HTTPS_BACKEND}")
- IF(HTTPS_BACKEND STREQUAL "SecureTransport")
- SET(SHA1_BACKEND "CommonCrypto")
- ELSEIF(HTTPS_BACKEND STREQUAL "WinHTTP")
- SET(SHA1_BACKEND "Win32")
- ELSEIF(HTTPS_BACKEND)
- SET(SHA1_BACKEND ${HTTPS_BACKEND})
- ELSE()
- ENDIF()
- IF(NOT HTTPS_BACKEND)
- SET(SHA1_BACKEND "CollisionDetection")
- ENDIF()
- message(STATUS "Using SHA1 backend ${SHA1_BACKEND}")
-ELSEIF(USE_SHA1 STREQUAL "Generic")
- SET(SHA1_BACKEND "Generic")
-# ELSEIF(NOT USE_SHA1)
-ELSE()
- MESSAGE(FATAL_ERROR "Invalid value for USE_SHA1: ${USE_SHA1}")
-ENDIF()
-
-IF(SHA1_BACKEND STREQUAL "CollisionDetection")
- SET(GIT_SHA1_COLLISIONDETECT 1)
- ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
- ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
- ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
- FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
-ELSEIF(SHA1_BACKEND STREQUAL "OpenSSL")
- # OPENSSL_FOUND should already be set, we're checking HTTPS_BACKEND
-
- SET(GIT_SHA1_OPENSSL 1)
- IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
- ELSE()
- LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
- ENDIF()
- FILE(GLOB SRC_SHA1 hash/sha1/openssl.*)
-ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto")
- SET(GIT_SHA1_COMMON_CRYPTO 1)
- FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
-ELSEIF(SHA1_BACKEND STREQUAL "mbedTLS")
- SET(GIT_SHA1_MBEDTLS 1)
- FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
- LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
- LIST(APPEND LIBGIT2_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(SHA1_BACKEND STREQUAL "Win32")
- SET(GIT_SHA1_WIN32 1)
- FILE(GLOB SRC_SHA1 hash/sha1/win32.*)
-ELSEIF(SHA1_BACKEND STREQUAL "Generic")
- FILE(GLOB SRC_SHA1 hash/sha1/generic.*)
-# ELSEIF(NOT USE_SHA1)
-ELSE()
- MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${SHA1_BACKEND}")
-ENDIF()
-
-ADD_FEATURE_INFO(SHA ON "using ${SHA1_BACKEND}")
diff -Nru cargo-0.47.0/debian/libgit2/cmake/Modules/SelectHTTPSBackend.cmake cargo-0.51.0/debian/libgit2/cmake/Modules/SelectHTTPSBackend.cmake
--- cargo-0.47.0/debian/libgit2/cmake/Modules/SelectHTTPSBackend.cmake 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/Modules/SelectHTTPSBackend.cmake 1970-01-01 00:00:00.000000000 +0000
@@ -1,127 +0,0 @@
-# Select the backend to use
-
-INCLUDE(SanitizeBool)
-
-# We try to find any packages our backends might use
-FIND_PACKAGE(OpenSSL)
-FIND_PACKAGE(mbedTLS)
-IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
- FIND_PACKAGE(Security)
- FIND_PACKAGE(CoreFoundation)
-ENDIF()
-
-# Auto-select TLS backend
-SanitizeBool(USE_HTTPS)
-IF (USE_HTTPS STREQUAL ON)
- IF (SECURITY_FOUND)
- IF (SECURITY_HAS_SSLCREATECONTEXT)
- SET(HTTPS_BACKEND "SecureTransport")
- ELSE()
- MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL")
- SET(HTTPS_BACKEND "OpenSSL")
- ENDIF()
- ELSEIF (WINHTTP)
- SET(HTTPS_BACKEND "WinHTTP")
- ELSEIF(OPENSSL_FOUND)
- SET(HTTPS_BACKEND "OpenSSL")
- ELSEIF(MBEDTLS_FOUND)
- SET(HTTPS_BACKEND "mbedTLS")
- ELSE()
- MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
- "Please pass the backend name explicitly (-DUSE_HTTPS=backend)")
- ENDIF()
-ELSEIF(USE_HTTPS)
- # HTTPS backend was explicitly set
- SET(HTTPS_BACKEND ${USE_HTTPS})
-ELSE()
- SET(HTTPS_BACKEND NO)
-ENDIF()
-
-IF(HTTPS_BACKEND)
- # Check that we can find what's required for the selected backend
- IF (HTTPS_BACKEND 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_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
- LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
- ELSEIF (HTTPS_BACKEND 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_LIBS ${OPENSSL_LIBRARIES})
- LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
- LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
- ELSEIF(HTTPS_BACKEND 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(CMAKE_SYSTEM_NAME MATCHES Darwin)
- # 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_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 (HTTPS_BACKEND STREQUAL "WinHTTP")
- # WinHTTP setup was handled in the WinHTTP-specific block above
- ELSE()
- MESSAGE(FATAL_ERROR "Asked for backend ${HTTPS_BACKEND} but it wasn't found")
- ENDIF()
-
- SET(GIT_HTTPS 1)
- ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${HTTPS_BACKEND}")
-ELSE()
- SET(GIT_HTTPS 0)
- ADD_FEATURE_INFO(HTTPS NO "")
-ENDIF()
diff -Nru cargo-0.47.0/debian/libgit2/cmake/PkgBuildConfig.cmake cargo-0.51.0/debian/libgit2/cmake/PkgBuildConfig.cmake
--- cargo-0.47.0/debian/libgit2/cmake/PkgBuildConfig.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/PkgBuildConfig.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,77 @@
+# 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 -Nru cargo-0.47.0/debian/libgit2/cmake/SanitizeBool.cmake cargo-0.51.0/debian/libgit2/cmake/SanitizeBool.cmake
--- cargo-0.47.0/debian/libgit2/cmake/SanitizeBool.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/SanitizeBool.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,20 @@
+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 -Nru cargo-0.47.0/debian/libgit2/cmake/SelectGSSAPI.cmake cargo-0.51.0/debian/libgit2/cmake/SelectGSSAPI.cmake
--- cargo-0.47.0/debian/libgit2/cmake/SelectGSSAPI.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/SelectGSSAPI.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,48 @@
+INCLUDE(SanitizeBool)
+
+# We try to find any packages our backends might use
+FIND_PACKAGE(GSSAPI)
+IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ 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_LIBS ${GSSFRAMEWORK_LIBRARIES})
+
+ SET(GIT_GSSFRAMEWORK 1)
+ ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${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_LIBS ${GSSAPI_LIBRARIES})
+
+ SET(GIT_GSSAPI 1)
+ ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${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(SPNEGO NO "SPNEGO authentication support")
+ENDIF()
diff -Nru cargo-0.47.0/debian/libgit2/cmake/SelectHashes.cmake cargo-0.51.0/debian/libgit2/cmake/SelectHashes.cmake
--- cargo-0.47.0/debian/libgit2/cmake/SelectHashes.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/SelectHashes.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,61 @@
+# Select a hash backend
+
+INCLUDE(SanitizeBool)
+
+# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
+
+SanitizeBool(USE_SHA1)
+IF(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 "WinHTTP")
+ SET(USE_SHA1 "Win32")
+ ELSEIF(USE_HTTPS)
+ SET(USE_SHA1 ${USE_HTTPS})
+ ELSE()
+ SET(USE_SHA1 "CollisionDetection")
+ ENDIF()
+ENDIF()
+
+IF(USE_SHA1 STREQUAL "CollisionDetection")
+ SET(GIT_SHA1_COLLISIONDETECT 1)
+ ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1)
+ ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
+ ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
+ FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
+ELSEIF(USE_SHA1 STREQUAL "OpenSSL")
+ # OPENSSL_FOUND should already be set, we're checking USE_HTTPS
+
+ SET(GIT_SHA1_OPENSSL 1)
+ IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ LIST(APPEND LIBGIT2_PC_LIBS "-lssl")
+ ELSE()
+ LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
+ ENDIF()
+ FILE(GLOB SRC_SHA1 hash/sha1/openssl.*)
+ELSEIF(USE_SHA1 STREQUAL "CommonCrypto")
+ SET(GIT_SHA1_COMMON_CRYPTO 1)
+ FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
+ELSEIF(USE_SHA1 STREQUAL "mbedTLS")
+ SET(GIT_SHA1_MBEDTLS 1)
+ FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
+ LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
+ LIST(APPEND LIBGIT2_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_SHA1 STREQUAL "Win32")
+ SET(GIT_SHA1_WIN32 1)
+ FILE(GLOB SRC_SHA1 hash/sha1/win32.*)
+ELSEIF(USE_SHA1 STREQUAL "Generic")
+ FILE(GLOB SRC_SHA1 hash/sha1/generic.*)
+ELSE()
+ MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
+ENDIF()
+
+list(SORT SRC_SHA1)
+
+ADD_FEATURE_INFO(SHA ON "using ${USE_SHA1}")
diff -Nru cargo-0.47.0/debian/libgit2/cmake/SelectHTTPSBackend.cmake cargo-0.51.0/debian/libgit2/cmake/SelectHTTPSBackend.cmake
--- cargo-0.47.0/debian/libgit2/cmake/SelectHTTPSBackend.cmake 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/cmake/SelectHTTPSBackend.cmake 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,120 @@
+INCLUDE(SanitizeBool)
+
+# We try to find any packages our backends might use
+FIND_PACKAGE(OpenSSL)
+FIND_PACKAGE(mbedTLS)
+IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ FIND_PACKAGE(Security)
+ FIND_PACKAGE(CoreFoundation)
+ENDIF()
+
+IF(USE_HTTPS)
+ # Auto-select TLS backend
+ SanitizeBool(USE_HTTPS)
+ 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 (WINHTTP)
+ 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_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_LIBS ${OPENSSL_LIBRARIES})
+ 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(CMAKE_SYSTEM_NAME MATCHES Darwin)
+ # 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_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 "WinHTTP")
+ # WinHTTP setup was handled in the WinHTTP-specific block above
+ ELSE()
+ MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
+ ENDIF()
+
+ SET(GIT_HTTPS 1)
+ ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
+ELSE()
+ SET(GIT_HTTPS 0)
+ ADD_FEATURE_INFO(HTTPS NO "")
+ENDIF()
diff -Nru cargo-0.47.0/debian/libgit2/CMakeLists.txt cargo-0.51.0/debian/libgit2/CMakeLists.txt
--- cargo-0.47.0/debian/libgit2/CMakeLists.txt 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/CMakeLists.txt 2021-04-07 03:36:48.000000000 +0000
@@ -11,21 +11,12 @@
# Install:
# > cmake --build . --target install
-PROJECT(libgit2 C)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
-CMAKE_POLICY(SET CMP0015 NEW)
-IF(POLICY CMP0051)
- CMAKE_POLICY(SET CMP0051 NEW)
-ENDIF()
-IF(POLICY CMP0042)
- CMAKE_POLICY(SET CMP0042 NEW)
-ENDIF()
-IF(POLICY CMP0054)
- CMAKE_POLICY(SET CMP0054 NEW)
-ENDIF()
+
+project(libgit2 VERSION "1.1.0" LANGUAGES C)
# Add find modules to the path
-SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/Modules/")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/")
INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists)
@@ -49,8 +40,6 @@
OPTION(BUILD_CLAR "Build Tests using the Clar suite" ON)
OPTION(BUILD_EXAMPLES "Build library usage example apps" OFF)
OPTION(BUILD_FUZZERS "Build the fuzz targets" OFF)
-OPTION(TAGS "Generate tags" OFF)
-OPTION(PROFILE "Generate profiling information" OFF)
OPTION(ENABLE_TRACE "Enables tracing support" ON)
OPTION(LIBGIT2_FILENAME "Name of the produced binary" OFF)
OPTION(USE_SSH "Link with libssh2 to enable SSH support" ON)
@@ -100,20 +89,10 @@
ENDIF()
IF(MSVC)
- # Enable MSVC CRTDBG memory leak reporting when in debug mode.
- OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
+ # Enable leak checking using the debugging C runtime.
+ OPTION(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF)
ENDIF()
-FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
-
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}")
-STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
-SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
-
-FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION \"([0-9.]+)\"$")
-STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION \"([0-9.]+)\"$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}")
-
IF (DEPRECATE_HARD)
ADD_DEFINITIONS(-DGIT_DEPRECATE_HARD)
ENDIF()
@@ -137,6 +116,11 @@
# /Gd - explicitly set cdecl calling convention
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
+ 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")
@@ -145,8 +129,8 @@
SET(CRT_FLAG_RELEASE "/MD")
ENDIF()
- IF (MSVC_CRTDBG)
- SET(GIT_MSVC_CRTDBG 1)
+ 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()
@@ -181,7 +165,12 @@
# /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}")
+ 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)
@@ -232,35 +221,27 @@
ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
ENDIF ()
- ENABLE_WARNINGS(documentation)
- DISABLE_WARNINGS(missing-field-initializers)
- 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(documentation)
+ disable_warnings(documentation-deprecated-sync)
+ disable_warnings(missing-field-initializers)
+ 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)
# 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()
-
- IF("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
- DISABLE_WARNINGS(documentation-deprecated-sync)
- ENDIF()
-
- IF (PROFILE)
- SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
- SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
- ENDIF ()
+ 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.
@@ -300,25 +281,6 @@
ADD_SUBDIRECTORY(tests)
ENDIF ()
-IF (TAGS)
- FIND_PROGRAM(CTAGS ctags)
- IF (NOT CTAGS)
- MESSAGE(FATAL_ERROR "Could not find ctags command")
- ENDIF ()
-
- FILE(GLOB_RECURSE SRC_ALL *.[ch])
-
- ADD_CUSTOM_COMMAND(
- OUTPUT tags
- COMMAND ${CTAGS} -a ${SRC_ALL}
- DEPENDS ${SRC_ALL}
- )
- ADD_CUSTOM_TARGET(
- do_tags ALL
- DEPENDS tags
- )
-ENDIF ()
-
IF (BUILD_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF ()
diff -Nru cargo-0.47.0/debian/libgit2/docs/changelog.md cargo-0.51.0/debian/libgit2/docs/changelog.md
--- cargo-0.47.0/debian/libgit2/docs/changelog.md 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/docs/changelog.md 2021-04-07 03:36:48.000000000 +0000
@@ -1,3 +1,111 @@
+vNext
+-----
+
+### Changes or improvements
+
+* Branch and tag name validation functions have been introduced:
+ `git_branch_name_is_valid` will check if a branch name is valid,
+ and `git_tag_name_is_valid` will check if a tag name is valid.
+
+* Some remote and reference validity checking functions have been
+ introduced with error reporting semantics. `git_remote_name_is_valid`
+ replaces `git_remote_is_valid_name`. `git_reference_name_is_valid`
+ replaces `git_reference_is_valid_name`. Tthe former functions are
+ deprecated.
+
+### Breaking CMake configuration changes
+
+The `MVSC_CRTDBG` configuration option is now `WIN32_LEAKCHECK`.
+
+v1.1
+----
+
+This is release v1.1, "Fernweh".
+
+### Changes or improvements
+
+* Our bundled PCRE dependency has been updated to 8.44.
+
+* The `refs/remotes/origin/HEAD` file will be created at clone time to
+ point to the origin's default branch.
+
+* libgit2 now uses the `__atomic_` intrinsics instead of `__sync_`
+ intrinsics on supported gcc and clang versions.
+
+* The `init.defaultBranch` setting is now respected and `master` is
+ no longer the hardcoded as the default branch name.
+
+* Patch files that do not contain an `index` line can now be parsed.
+
+* Configuration files with multi-line values can now contain quotes
+ split across multiple lines.
+
+* Windows clients now attempt to use TLS1.3 when available.
+
+* Servers that request an upgrade to a newer HTTP version are
+ silently ignored instead of erroneously failing.
+
+* Users can pass `NULL` to the options argument to
+ `git_describe_commit`.
+
+* Clones and fetches of very large packfiles now succeeds on 32-bit
+ platforms.
+
+* Custom reference database backends can now handle the repository's
+ `HEAD` correctly.
+
+* Repositories with a large number of packfiles no longer exhaust the
+ number of file descriptors.
+
+* The test framework now supports TAP output when the `-t` flag is
+ specified.
+
+* The test framework can now specify an exact match to a test
+ function using a trailing `$`.
+
+* All checkout types support `GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH`.
+
+* `git_blame` now can ignore whitespace changes using the option
+ `GIT_BLAME_IGNORE_WHITESPACE`.
+
+* Several new examples have been created, including an examples for
+ commit, add and push.
+
+* Mode changes during rename are now supported in patch application.
+
+* `git_checkout_head` now correctly removes untracked files in a
+ subdirectory when the `FORCE | REMOVE_UNTRACKED` options are specified.
+
+v1.0.1
+------
+
+This is a bugfix release with the following changes:
+
+- Calculating information about renamed files during merges is more
+ efficient because dissimilarity about files is now being cached and
+ no longer needs to be recomputed.
+
+- The `git_worktree_prune_init_options` has been correctly restored for
+ backward compatibility. In v1.0 it was incorrectly deprecated with a
+ typo.
+
+- The optional ntlmclient dependency now supports NetBSD.
+
+- A bug where attempting to stash on a bare repository may have failed
+ has been fixed.
+
+- Configuration files that are unreadable due to permissions are now
+ silently ignored, and treated as if they do not exist. This matches
+ git's behavior; previously this case would have been an error.
+
+- v4 index files are now correctly written; previously we would read
+ them correctly but would not write the prefix-compression accurately,
+ causing corruption.
+
+- A bug where the smart HTTP transport could not read large data packets
+ has been fixed. Previously, fetching from servers like Gerrit, that
+ sent large data packets, would error.
+
v1.0
----
diff -Nru cargo-0.47.0/debian/libgit2/docs/coding-style.md cargo-0.51.0/debian/libgit2/docs/coding-style.md
--- cargo-0.47.0/debian/libgit2/docs/coding-style.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/docs/coding-style.md 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,364 @@
+# libgit2 Coding Style
+
+This documentation describes the preferred coding style for the libgit2 project.
+While not all parts of our code base conform to this coding style, the outlined
+rules are what we aim for.
+
+Note that in no case do we accept changes that convert huge parts of the code
+base to use our coding style. Instead, it is encouraged to modernize small parts
+of code you're going to modify anyway for a given change you want to introduce.
+A good rule to follow is the Boy Scout Rule: "Leave the campground cleaner than
+you found it."
+
+## C Coding Style
+
+The following sections define the coding style for all code files and headers.
+
+### Indentation and Alignment
+
+Code is indented by tabs, where a tab is 8 spaces. Each opening scope increases
+the indentation level.
+
+```c
+int foobar(int void)
+{
+ if (condition)
+ doit();
+ /* Body */
+}
+```
+
+Switch statements have their `case`s aligned with the `switch` keyword. Case
+bodies are indented by an additional level. Case bodies should not open their
+own scope to declare variables.
+
+```c
+switch (c) {
+case 'a':
+case 'b':
+ return 0;
+default:
+ return -1;
+}
+```
+
+Multi-line conditions should be aligned with the opening brace of the current
+statement:
+
+```c
+if (one_very_long_condition(c) &&
+ another_very_long_condition(c))
+ doit();
+```
+
+### Spaces
+
+There must be no space between the function and its arguments, arguments must be
+separated by a space:
+
+```c
+int doit(int first_arg, int second_arg);
+doit(1, 2);
+```
+
+For any binary or ternary operators, the arguments and separator must be
+separated by a space:
+
+```c
+1 + 2;
+x ? x : NULL;
+```
+
+Unary operators do not have a space between them and the argument they refer to:
+
+```c
+*c
+&c
+```
+
+The `sizeof` operator always must not have a space and must use braces around
+the type:
+
+```
+sizeof(int)
+```
+
+There must be a space after the keywords `if`, `switch`, `case`, `do` and
+`while`.
+
+### Braces
+
+Functions must have their opening brace on the following line:
+
+```c
+void foobar(void)
+{
+ doit();
+}
+```
+
+For conditions, braces should be placed on the same line as the condition:
+
+```c
+if (condition(c)) {
+ doit();
+ dothat();
+}
+
+while (true) {
+ doit();
+}
+```
+
+In case a condition's body has a single line, only, it's allowed to omit braces,
+except if any of its `else if` or `else` branches has more than one line:
+
+```c
+if (condition(c))
+ doit();
+
+if (condition(c))
+ doit();
+else if (other_condition(c))
+ doit();
+
+/* This example must use braces as the `else if` requires them. */
+if (condition(c)) {
+ doit();
+} else if (other_condition(c)) {
+ doit();
+ dothat();
+} else {
+ abort();
+}
+```
+
+### Comments
+
+Comments must use C-style `/* */` comments. C++-style `// `comments are not
+allowed in our codebase. This is a strict requirement as libgit2 tries to be
+compliant with the ISO C90 standard, which only allows C-style comments.
+
+Single-line comments may have their opening and closing tag on the same line:
+
+```c
+/* This is a short comment. */
+```
+
+For multi-line comments, the opening and closing tag should be empty:
+
+```c
+/*
+ * This is a rather long and potentially really unwiedly but informative
+ * multiline comment that helps quite a lot.
+ */
+```
+
+Public functions must have documentation that explain their usage, internal
+functions should have a comment. We use Docurium to generate documentation
+derived from these comments, which uses syntax similar to Doxygen. The first
+line should be a short summary of what the function does. More in-depth
+explanation should be separated from that first line by an empty line.
+Parameters and return values should be documented via `@return` and `@param`
+tags:
+
+```c
+/*
+ * Froznicate the string.
+ *
+ * Froznicate the string by foobaring its internal structure into a more obvious
+ * translation. Note that the returned string is a newly allocated string that
+ * shall be `free`d by the caller.
+ *
+ * @param s String to froznicate
+ * @return A newly allocated string or `NULL` in case an error occurred.
+ * /
+char *froznicate(const char *s);
+```
+
+### Variables
+
+Variables must be declared at the beginning of their scope. This is a strict
+requirement as libgit2 tries to be compliant with the ISO C90 standard, which
+forbids mixed declarations and code:
+
+```c
+void foobar(void)
+{
+ char *c = NULL;
+ int a, b;
+
+ a = 0;
+ b = 1;
+
+ return c;
+}
+```
+
+### Naming
+
+Variables must have all-lowercase names. In case a variable name has multiple
+words, words should be separated by an underscore `_` character. While
+recommended to use descriptive naming, common variable names like `i` for
+indices are allowed.
+
+All public functions must have a `git` prefix as well as a prefix indicating
+their respective subsystem. E.g. a function that opens a repository should be
+called `git_repository_open()`. Functions that are not public but declared in
+an internal header file for use by other subsystems should follow the same
+naming pattern. File-local static functions must not have a `git` prefix, but
+should have a prefix indicating their respective subsystem.
+
+All structures declared in the libgit2 project must have a `typedef`, we do not
+use `struct type` variables. Type names follow the same schema as functions.
+
+### Error Handling
+
+The libgit2 project mostly uses error codes to indicate errors. Error codes are
+always of type `int`, where `0` indicates success and a negative error code
+indicates an error case. In some cases, positive error codes may be used to
+indicate special cases. Returned values that are not an error code should be
+returned via an out parameter. Out parameters must always come first in the list
+of arguments.
+
+```c
+int doit(const char **out, int arg)
+{
+ if (!arg)
+ return -1;
+ *out = "Got an argument";
+ return 0;
+}
+```
+
+To avoid repetitive and fragile error handling in case a function has resources
+that need to be free'd, we use `goto out`s:
+
+```c
+int doit(char **out, int arg)
+{
+ int error = 0;
+ char *c;
+
+ c = malloc(strlen("Got an argument") + 1);
+ if (!c) {
+ error = -1;
+ goto out;
+ }
+
+ if (!arg) {
+ error = -1;
+ goto out;
+ }
+
+ strcpy(c, "Got an argument")
+ *out = c;
+
+out:
+ if (error)
+ free(c);
+ return error;
+}
+```
+
+When calling functions that return an error code, you should assign the error
+code to an `error` variable and, in case an error case is indicated and no
+custom error handling is required, return that error code:
+
+```c
+int foobar(void)
+{
+ int error;
+
+ if ((error = doit()) < 0)
+ return error;
+
+ return 0;
+}
+```
+
+When doing multiple function calls where all of the functions return an error
+code, it's common practice to chain these calls together:
+
+```c
+int doit(void)
+{
+ int error;
+
+ if ((error = dothis()) < 0 ||
+ (error = dothat()) < 0)
+ return error;
+
+ return 0;
+}
+```
+
+## CMake Coding Style
+
+The following section defines the coding style for our CMake build system.
+
+### Indentation
+
+Code is indented by tabs, where a tab is 8 spaces. Each opening scope increases
+the indentation level.
+
+```cmake
+if(CONDITION)
+ doit()
+endif()
+```
+
+### Spaces
+
+There must be no space between keywords and their opening brace. While this is
+the same as in our C codebase for function calls, this also applies to
+conditional keywords. This is done to avoid the awkward-looking `else ()`
+statement.
+
+```cmake
+if(CONDITION)
+ doit()
+else()
+ dothat()
+endif()
+```
+
+### Case
+
+While CMake is completely case-insensitive when it comes to function calls, we
+want to agree on a common coding style for this. To reduce the danger of
+repetitive strain injuries, all function calls should be lower-case (NB: this is
+not currently the case yet, but introduced as a new coding style by this
+document).
+
+Variables are written all-uppercase. In contrast to functions, variables are
+case-sensitive in CMake. As CMake itself uses upper-case variables in all
+places, we should follow suit and do the same.
+
+Control flow keywords must be all lowercase. In contrast to that, test keywords
+must be all uppercase:
+
+```cmake
+if(NOT CONDITION)
+ doit()
+elseif(FOO AND BAR)
+ dothat()
+endif()
+```
+
+### Targets
+
+CMake code should not use functions that modify the global scope but prefer
+their targeted equivalents, instead. E.g. instead of using
+`include_directories()`, you must use `target_include_directories()`. An
+exception to this rule is setting up global compiler flags like warnings or
+flags required to set up the build type.
+
+### Dependencies
+
+Dependencies should not be discovered or set up in the main "CMakeLists.txt"
+module. Instead, they should either have their own module in our top-level
+"cmake/" directory or have a "CMakeLists.txt" in their respective "deps/"
+directory in case it is a vendored library. All dependencies should expose
+interface library targets that can be linked against with
+`target_link_libraries()`.
diff -Nru cargo-0.47.0/debian/libgit2/git.git-authors cargo-0.51.0/debian/libgit2/git.git-authors
--- cargo-0.47.0/debian/libgit2/git.git-authors 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/git.git-authors 2021-04-07 03:36:48.000000000 +0000
@@ -25,9 +25,9 @@
# contributed code (possibly with some exceptions)
# "no" means the author does not consent
# "ask" means that the contributor wants to give/withhold
-# his/her consent on a patch-by-patch basis.
+# their consent on a patch-by-patch basis.
# "???" means the person is a prominent contributor who has
-# not yet made his/her standpoint clear.
+# 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.
diff -Nru cargo-0.47.0/debian/libgit2/.github/workflows/codeql.yml cargo-0.51.0/debian/libgit2/.github/workflows/codeql.yml
--- cargo-0.47.0/debian/libgit2/.github/workflows/codeql.yml 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/.github/workflows/codeql.yml 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,36 @@
+name: "CodeQL"
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: '21 3 * * 1'
+
+env:
+ docker-registry: docker.pkg.github.com
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ with:
+ languages: 'cpp'
+
+ - name: Build
+ run: |
+ mkdir build
+ cd build
+ cmake .. -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+ cmake --build .
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff -Nru cargo-0.47.0/debian/libgit2/.github/workflows/main.yml cargo-0.51.0/debian/libgit2/.github/workflows/main.yml
--- cargo-0.47.0/debian/libgit2/.github/workflows/main.yml 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/.github/workflows/main.yml 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,296 @@
+# Continuous integration and pull request validation builds for the
+# master and maintenance branches.
+name: CI Build
+
+on:
+ push:
+ branches: [ master, maint/* ]
+ pull_request:
+ branches: [ master, maint/* ]
+
+env:
+ docker-registry: docker.pkg.github.com
+ docker-config-path: 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.
+ build_containers:
+ name: Create docker image
+ strategy:
+ matrix:
+ container:
+ - name: xenial
+ - name: bionic
+ - name: focal
+ - 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
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ if: github.event_name == 'push'
+ - 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 }}/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 == 'push'
+ - 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 }} ${BASE_ARG} -f ${{ env.dockerfile }} .
+ docker push ${{ env.docker-registry-container-sha }}
+ working-directory: ${{ env.docker-config-path }}
+ if: github.event_name == 'push' && env.docker-container-exists != 'true'
+
+ # 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:
+ name: Build
+ needs: [ build_containers ]
+ strategy:
+ matrix:
+ platform:
+ - # Xenial, GCC, OpenSSL
+ 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
+ os: ubuntu-latest
+ - # Xenial, GCC, mbedTLS
+ container:
+ name: xenial
+ env:
+ CC: gcc
+ CMAKE_GENERATOR: Ninja
+ CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ os: ubuntu-latest
+ - # Xenial, Clang, OpenSSL
+ container:
+ name: xenial
+ env:
+ CC: clang
+ CMAKE_GENERATOR: Ninja
+ CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ os: ubuntu-latest
+ - # Xenial, Clang, mbedTLS
+ container:
+ name: xenial
+ env:
+ CC: clang
+ CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ CMAKE_GENERATOR: Ninja
+ os: ubuntu-latest
+ - # Focal, Clang 10, mbedTLS, MemorySanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ os: ubuntu-latest
+ - # Focal, Clang 10, OpenSSL, UndefinedBehaviorSanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ os: ubuntu-latest
+ - # Focal, Clang 10, OpenSSL, ThreadSanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1
+ os: ubuntu-latest
+ - # macOS
+ os: macos-10.15
+ 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
+ setup-script: osx
+ - # Windows amd64 Visual Studio
+ os: windows-2019
+ env:
+ ARCH: amd64
+ CMAKE_GENERATOR: Visual Studio 16 2019
+ CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ - # Windows x86 Visual Studio
+ os: windows-2019
+ env:
+ ARCH: x86
+ CMAKE_GENERATOR: Visual Studio 16 2019
+ CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ - # Windows amd64 mingw
+ os: windows-2019
+ 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
+ - # Windows x86 mingw
+ os: windows-2019
+ setup-script: mingw
+ env:
+ ARCH: x86
+ CMAKE_GENERATOR: MinGW Makefiles
+ CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
+ 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
+ fail-fast: false
+ env: ${{ matrix.platform.env }}
+ runs-on: ${{ matrix.platform.os }}
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Set up build environment
+ run: ci/setup-${{ matrix.platform.setup-script }}.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: Download container
+ run: |
+ "${{ github.workspace }}/ci/getcontainer.sh" "${{ matrix.platform.container.name }}" "${{ matrix.platform.container.dockerfile }}"
+ env:
+ DOCKER_REGISTRY: ${{ env.docker-registry }}
+ GITHUB_TOKEN: ${{ secrets.github_token }}
+ working-directory: ${{ env.docker-config-path }}
+ if: matrix.platform.container.name != ''
+ - name: Create container
+ run: docker build -t ${{ env.docker-registry-container-sha }} -f ${{ env.dockerfile }} .
+ working-directory: ${{ env.docker-config-path }}
+ if: matrix.platform.container.name != '' && env.docker-container-exists != 'true'
+ - name: Build and test
+ run: |
+ export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
+
+ if [ -n "${{ matrix.platform.container.name }}" ]; then
+ docker run \
+ --rm \
+ -v "$(pwd):/home/libgit2/source" \
+ -w /home/libgit2/source \
+ -e ASAN_SYMBOLIZER_PATH \
+ -e CC \
+ -e CFLAGS \
+ -e CMAKE_GENERATOR \
+ -e CMAKE_OPTIONS \
+ -e GITTEST_NEGOTIATE_PASSWORD \
+ -e PKG_CONFIG_PATH \
+ -e SKIP_NEGOTIATE_TESTS \
+ -e SKIP_SSH_TESTS \
+ -e TSAN_OPTIONS \
+ ${{ env.docker-registry-container-sha }} \
+ /bin/bash -c "mkdir build && cd build && ../ci/build.sh && ../ci/test.sh"
+ else
+ mkdir build && cd build
+ ../ci/build.sh
+ ../ci/test.sh
+ fi
+ shell: bash
+
+ # Generate documentation using docurium. We'll upload the documentation
+ # as a build artifact so that it can be reviewed as part of a pull
+ # request or in a forked build. For CI builds in the main repository's
+ # master branch, we'll push the gh-pages branch back up so that it is
+ # published to our documentation site.
+ documentation:
+ name: Generate documentation
+ needs: [build_containers]
+ runs-on: ubuntu-latest
+ steps:
+ - name: Setup defaults
+ run: |
+ if [ "${{ matrix.container.dockerfile }}" = "" ]; then
+ echo "dockerfile=${{ matrix.container.dockerfile }}" >> $GITHUB_ENV
+ else
+ echo "dockerfile=${{ matrix.container.dockerfile }}" >> $GITHUB_ENV
+ fi
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Generate documentation
+ run: |
+ git config user.name 'Documentation Generation'
+ git config user.email 'libgit2@users.noreply.github.com'
+ git branch gh-pages origin/gh-pages
+ docker login https://${{ env.docker-registry }} -u ${{ github.actor }} -p ${{ github.token }}
+ docker run \
+ --rm \
+ -v "$(pwd):/home/libgit2/source" \
+ -w /home/libgit2/source \
+ ${{ env.docker-registry }}/${{ github.repository }}/docurium:latest \
+ cm doc api.docurium
+ git checkout gh-pages
+ zip --exclude .git/\* --exclude .gitignore --exclude .gitattributes -r api-documentation.zip .
+ - uses: actions/upload-artifact@v2
+ name: Upload artifact
+ with:
+ name: api-documentation
+ path: api-documentation.zip
+ - name: Push documentation branch
+ run: git push origin gh-pages
+ if: github.event_name == 'push' && github.repository == 'libgit2/libgit2'
diff -Nru cargo-0.47.0/debian/libgit2/.github/workflows/nightly.yml cargo-0.51.0/debian/libgit2/.github/workflows/nightly.yml
--- cargo-0.47.0/debian/libgit2/.github/workflows/nightly.yml 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/.github/workflows/nightly.yml 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,265 @@
+# Nightly build for the master branch across multiple targets.
+name: Nightly Build
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: '15 1 * * *'
+
+env:
+ docker-registry: docker.pkg.github.com
+ docker-config-path: ci/docker
+
+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:
+ name: Build
+ strategy:
+ matrix:
+ platform:
+ - # Xenial, GCC, OpenSSL
+ 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
+ os: ubuntu-latest
+ - # Xenial, GCC, mbedTLS
+ container:
+ name: xenial
+ env:
+ CC: gcc
+ CMAKE_GENERATOR: Ninja
+ CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ os: ubuntu-latest
+ - # Xenial, Clang, OpenSSL
+ container:
+ name: xenial
+ env:
+ CC: clang
+ CMAKE_GENERATOR: Ninja
+ CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ os: ubuntu-latest
+ - # Xenial, Clang, mbedTLS
+ container:
+ name: xenial
+ env:
+ CC: clang
+ CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ CMAKE_GENERATOR: Ninja
+ os: ubuntu-latest
+ - # Xenial, GCC, thread-free
+ container:
+ name: xenial
+ env:
+ CC: gcc
+ CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
+ CMAKE_GENERATOR: Ninja
+ os: ubuntu-latest
+ - # Focal, Clang 10, mbedTLS, MemorySanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ os: ubuntu-latest
+ - # Focal, Clang 10, OpenSSL, UndefinedBehaviorSanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ os: ubuntu-latest
+ - # Focal, Clang 10, OpenSSL, ThreadSanitizer
+ container:
+ name: focal
+ env:
+ CC: clang-10
+ 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
+ CMAKE_GENERATOR: Ninja
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+ TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1
+ os: ubuntu-latest
+ - # macOS
+ os: macos-10.15
+ 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
+ setup-script: osx
+ - # Windows amd64 Visual Studio
+ os: windows-2019
+ env:
+ ARCH: amd64
+ CMAKE_GENERATOR: Visual Studio 16 2019
+ CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ - # Windows x86 Visual Studio
+ os: windows-2019
+ env:
+ ARCH: x86
+ CMAKE_GENERATOR: Visual Studio 16 2019
+ CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
+ SKIP_SSH_TESTS: true
+ SKIP_NEGOTIATE_TESTS: true
+ - # Windows amd64 mingw
+ os: windows-2019
+ 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
+ - # Windows x86 mingw
+ os: windows-2019
+ setup-script: mingw
+ env:
+ ARCH: x86
+ CMAKE_GENERATOR: MinGW Makefiles
+ CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
+ 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
+ - # 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
+ RUN_INVASIVE_TESTS: true
+ os: ubuntu-latest
+ - # 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
+ RUN_INVASIVE_TESTS: true
+ os: ubuntu-latest
+ - # 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
+ RUN_INVASIVE_TESTS: true
+ SKIP_PROXY_TESTS: true
+ os: ubuntu-latest
+ - # 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
+ RUN_INVASIVE_TESTS: true
+ SKIP_PROXY_TESTS: true
+ os: ubuntu-latest
+ fail-fast: false
+ env: ${{ matrix.platform.env }}
+ runs-on: ${{ matrix.platform.os }}
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Set up build environment
+ run: ci/setup-${{ matrix.platform.setup-script }}.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: Download container
+ run: |
+ "${{ github.workspace }}/ci/getcontainer.sh" "${{ matrix.platform.container.name }}" "${{ matrix.platform.container.dockerfile }}"
+ env:
+ DOCKER_REGISTRY: ${{ env.docker-registry }}
+ GITHUB_TOKEN: ${{ secrets.github_token }}
+ working-directory: ${{ env.docker-config-path }}
+ if: matrix.platform.container.name != ''
+ - name: Create container
+ run: docker build -t ${{ env.docker-registry-container-sha }} -f ${{ env.dockerfile }} .
+ working-directory: ${{ env.docker-config-path }}
+ if: matrix.platform.container.name != '' && env.docker-container-exists != 'true'
+ - name: Build and test
+ run: |
+ export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}"
+
+ if [ -n "${{ matrix.platform.container.name }}" ]; then
+ docker run \
+ --rm \
+ -v "$(pwd):/home/libgit2/source" \
+ -w /home/libgit2/source \
+ -e ASAN_SYMBOLIZER_PATH \
+ -e CC \
+ -e CFLAGS \
+ -e CMAKE_GENERATOR \
+ -e CMAKE_OPTIONS \
+ -e GITTEST_NEGOTIATE_PASSWORD \
+ -e PKG_CONFIG_PATH \
+ -e SKIP_NEGOTIATE_TESTS \
+ -e SKIP_SSH_TESTS \
+ -e TSAN_OPTIONS \
+ ${{ env.docker-registry-container-sha }} \
+ /bin/bash -c "mkdir build && cd build && ../ci/build.sh && ../ci/test.sh"
+ else
+ mkdir build && cd build
+ ../ci/build.sh
+ ../ci/test.sh
+ fi
+ shell: bash
+
+ coverity:
+ name: Coverity
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Download container
+ run: |
+ "${{ github.workspace }}/ci/getcontainer.sh" xenial
+ env:
+ DOCKER_REGISTRY: ${{ env.docker-registry }}
+ GITHUB_TOKEN: ${{ secrets.github_token }}
+ working-directory: ${{ env.docker-config-path }}
+ - name: Run Coverity
+ run: ci/coverity.sh
+ env:
+ COVERITY_TOKEN: ${{ secrets.coverity_token }}
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/annotated_commit.h cargo-0.51.0/debian/libgit2/include/git2/annotated_commit.h
--- cargo-0.47.0/debian/libgit2/include/git2/annotated_commit.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/annotated_commit.h 2021-04-07 03:36:48.000000000 +0000
@@ -78,7 +78,7 @@
const git_oid *id);
/**
- * Creates a `git_annotated_comit` from a revision string.
+ * 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
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/blame.h cargo-0.51.0/debian/libgit2/include/git2/blame.h
--- cargo-0.47.0/debian/libgit2/include/git2/blame.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/blame.h 2021-04-07 03:36:48.000000000 +0000
@@ -47,6 +47,8 @@
* 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;
/**
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/blob.h cargo-0.51.0/debian/libgit2/include/git2/blob.h
--- cargo-0.47.0/debian/libgit2/include/git2/blob.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/blob.h 2021-04-07 03:36:48.000000000 +0000
@@ -84,7 +84,7 @@
* time.
*
* @param blob pointer to the blob
- * @return the pointer
+ * @return the pointer, or NULL on error
*/
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/branch.h cargo-0.51.0/debian/libgit2/include/git2/branch.h
--- cargo-0.47.0/debian/libgit2/include/git2/branch.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/branch.h 2021-04-07 03:36:48.000000000 +0000
@@ -304,6 +304,18 @@
*/
GIT_EXTERN(int) git_branch_upstream_remote(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 -Nru cargo-0.47.0/debian/libgit2/include/git2/cert.h cargo-0.51.0/debian/libgit2/include/git2/cert.h
--- cargo-0.47.0/debian/libgit2/include/git2/cert.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/cert.h 2021-04-07 03:36:48.000000000 +0000
@@ -80,8 +80,19 @@
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,
+} git_cert_ssh_raw_type_t;
+
/**
* Hostkey information taken from libssh2
*/
@@ -89,28 +100,45 @@
git_cert parent; /**< The parent cert */
/**
- * A hostkey type from libssh2, either
- * `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
+ * A bitmask containing the available fields.
*/
git_cert_ssh_t type;
/**
- * Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
+ * 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
+ * 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
+ * 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;
/**
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/common.h cargo-0.51.0/debian/libgit2/include/git2/common.h
--- cargo-0.47.0/debian/libgit2/include/git2/common.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/common.h 2021-04-07 03:36:48.000000000 +0000
@@ -205,7 +205,9 @@
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_ENABLE_HTTP_EXPECT_CONTINUE,
+ GIT_OPT_GET_MWINDOW_FILE_LIMIT,
+ GIT_OPT_SET_MWINDOW_FILE_LIMIT
} git_libgit2_opt_t;
/**
@@ -227,8 +229,18 @@
*
* * 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
+ * > 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)
*
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/deprecated.h cargo-0.51.0/debian/libgit2/include/git2/deprecated.h
--- cargo-0.47.0/debian/libgit2/include/git2/deprecated.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/deprecated.h 2021-04-07 03:36:48.000000000 +0000
@@ -102,7 +102,11 @@
GIT_EXTERN(int) git_blob_create_frombuffer(
git_oid *id, git_repository *repo, const void *buffer, size_t len);
-/** Deprecated in favor of @see git_blob_filter */
+/** 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,
@@ -233,7 +237,7 @@
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
/**
- * Indicates that an out-of-memory situation occured. This is an alias
+ * 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
@@ -336,10 +340,32 @@
/**@}*/
-/** @name Deprecated Reference Constants
+/** @name Deprecated Remote Functions
*
- * These enumeration values are retained for backward compatibility. The
- * newer versions of these values should be preferred in all new code.
+ * 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.
@@ -360,6 +386,23 @@
#define GIT_REF_FORMAT_REFSPEC_PATTERN GIT_REFERENCE_FORMAT_REFSPEC_PATTERN
#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,
@@ -524,6 +567,42 @@
/**@}*/
+/** @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 Options Initialization Functions
*
* These functions are retained for backward compatibility. The newer
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/errors.h cargo-0.51.0/debian/libgit2/include/git2/errors.h
--- cargo-0.47.0/debian/libgit2/include/git2/errors.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/errors.h 2021-04-07 03:36:48.000000000 +0000
@@ -107,7 +107,8 @@
GIT_ERROR_PATCH,
GIT_ERROR_WORKTREE,
GIT_ERROR_SHA1,
- GIT_ERROR_HTTP
+ GIT_ERROR_HTTP,
+ GIT_ERROR_INTERNAL
} git_error_t;
/**
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/index.h cargo-0.51.0/debian/libgit2/include/git2/index.h
--- cargo-0.47.0/debian/libgit2/include/git2/index.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/index.h 2021-04-07 03:36:48.000000000 +0000
@@ -555,8 +555,7 @@
*
* 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. The `id` and the `file_size` of the 'entry' are updated with the
- * real value of the blob.
+ * added.
*
* This forces the file to be added to the index, not looking
* at gitignore rules. Those rules can be evaluated through
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/pack.h cargo-0.51.0/debian/libgit2/include/git2/pack.h
--- cargo-0.47.0/debian/libgit2/include/git2/pack.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/pack.h 2021-04-07 03:36:48.000000000 +0000
@@ -155,7 +155,7 @@
* Write the new pack and corresponding index file to path.
*
* @param pb The packbuilder
- * @param path to the directory where the packfile and index should be stored
+ * @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)
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/refs.h cargo-0.51.0/debian/libgit2/include/git2/refs.h
--- cargo-0.47.0/debian/libgit2/include/git2/refs.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/refs.h 2021-04-07 03:36:48.000000000 +0000
@@ -743,10 +743,11 @@
* 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 1 if the reference name is acceptable; 0 if it isn't
+ * @return 0 on success or an error code
*/
-GIT_EXTERN(int) git_reference_is_valid_name(const char *refname);
+GIT_EXTERN(int) git_reference_name_is_valid(int *valid, const char *refname);
/**
* Get the reference's short name
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/remote.h cargo-0.51.0/debian/libgit2/include/git2/remote.h
--- cargo-0.47.0/debian/libgit2/include/git2/remote.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/remote.h 2021-04-07 03:36:48.000000000 +0000
@@ -915,10 +915,11 @@
/**
* 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 1 if the reference name is acceptable; 0 if it isn't
+ * @return 0 on success or an error code
*/
-GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
+int git_remote_name_is_valid(int *valid, const char *remote_name);
/**
* Delete an existing persisted remote.
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/strarray.h cargo-0.51.0/debian/libgit2/include/git2/strarray.h
--- cargo-0.47.0/debian/libgit2/include/git2/strarray.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/strarray.h 2021-04-07 03:36:48.000000000 +0000
@@ -25,20 +25,16 @@
} git_strarray;
/**
- * Close a string array object
- *
- * This method should be called on `git_strarray` objects where the strings
- * array is allocated and contains allocated strings, such as what you
- * would get from `git_strarray_copy()`. Not doing so, will result in a
- * memory leak.
+ * 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 (it is more commonly embedded
- * inside another struct or created on the stack).
+ * never allocate that object directly itself.
*
- * @param array git_strarray from which to free string data
+ * @param array The git_strarray that contains strings to free
*/
-GIT_EXTERN(void) git_strarray_free(git_strarray *array);
+GIT_EXTERN(void) git_strarray_dispose(git_strarray *array);
/**
* Copy a string array object from source to target.
diff -Nru cargo-0.47.0/debian/libgit2/include/git2/tag.h cargo-0.51.0/debian/libgit2/include/git2/tag.h
--- cargo-0.47.0/debian/libgit2/include/git2/tag.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/tag.h 2021-04-07 03:36:48.000000000 +0000
@@ -365,6 +365,18 @@
*/
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 -Nru cargo-0.47.0/debian/libgit2/include/git2/version.h cargo-0.51.0/debian/libgit2/include/git2/version.h
--- cargo-0.47.0/debian/libgit2/include/git2/version.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/include/git2/version.h 2021-04-07 03:36:48.000000000 +0000
@@ -7,12 +7,12 @@
#ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__
-#define LIBGIT2_VERSION "1.0.0"
+#define LIBGIT2_VERSION "1.1.0"
#define LIBGIT2_VER_MAJOR 1
-#define LIBGIT2_VER_MINOR 0
+#define LIBGIT2_VER_MINOR 1
#define LIBGIT2_VER_REVISION 0
#define LIBGIT2_VER_PATCH 0
-#define LIBGIT2_SOVERSION "1.0"
+#define LIBGIT2_SOVERSION "1.1"
#endif
diff -Nru cargo-0.47.0/debian/libgit2/package.json cargo-0.51.0/debian/libgit2/package.json
--- cargo-0.47.0/debian/libgit2/package.json 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/package.json 2021-04-07 03:36:48.000000000 +0000
@@ -1,6 +1,6 @@
{
"name": "libgit2",
- "version": "0.27.0",
+ "version": "1.1.0",
"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 -Nru cargo-0.47.0/debian/libgit2/README.md cargo-0.51.0/debian/libgit2/README.md
--- cargo-0.47.0/debian/libgit2/README.md 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/README.md 2021-04-07 03:36:48.000000000 +0000
@@ -3,10 +3,10 @@
| Build Status | |
| ------------ | - |
-| **master** branch CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=master)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=master) |
-| **v0.99 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.99)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.99) |
-| **v0.28 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.28)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.28) |
-| **Nightly** builds | [![Azure Pipelines Build Status](https://libgit2.visualstudio.com/libgit2/_apis/build/status/nightly?branchName=master&label=Full+Build)](https://libgit2.visualstudio.com/libgit2/_build/latest?definitionId=9&branchName=master) [![Coverity Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/coverity?branchName=master&label=Coverity+Build)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=21?branchName=master) [![Coverity Scan Build Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) |
+| **master** branch CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush) |
+| **v1.1 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.1&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.1) |
+| **v1.0 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v1.0)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v1.0) |
+| **Nightly** builds | [![Nightly Build](https://github.com/libgit2/libgit2/workflows/Nightly%20Build/badge.svg)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22Nightly+Build%22) [![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
@@ -47,6 +47,7 @@
* [Compiler and linker options](#compiler-and-linker-options)
* [MacOS X](#macos-x)
* [Android](#android)
+ * [MinGW](#mingw)
* [Language Bindings](#language-bindings)
* [How Can I Contribute?](#how-can-i-contribute)
* [License](#license)
@@ -304,6 +305,20 @@
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
==================================
diff -Nru cargo-0.47.0/debian/libgit2/script/release.py cargo-0.51.0/debian/libgit2/script/release.py
--- cargo-0.47.0/debian/libgit2/script/release.py 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/script/release.py 2021-04-07 03:36:48.000000000 +0000
@@ -40,6 +40,15 @@
'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()
@@ -56,6 +65,17 @@
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()
@@ -155,7 +175,7 @@
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 authenitcate as')
+ 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()
diff -Nru cargo-0.47.0/debian/libgit2/script/sanitizers.supp cargo-0.51.0/debian/libgit2/script/sanitizers.supp
--- cargo-0.47.0/debian/libgit2/script/sanitizers.supp 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/script/sanitizers.supp 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,4 @@
+[undefined]
+# This library allows unaligned access on Intel-like processors. Prevent UBSan
+# from complaining about that.
+fun:sha1_compression_states
diff -Nru cargo-0.47.0/debian/libgit2/script/thread-sanitizer.supp cargo-0.51.0/debian/libgit2/script/thread-sanitizer.supp
--- cargo-0.47.0/debian/libgit2/script/thread-sanitizer.supp 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/script/thread-sanitizer.supp 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,26 @@
+# 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 -Nru cargo-0.47.0/debian/libgit2/src/allocators/failalloc.c cargo-0.51.0/debian/libgit2/src/allocators/failalloc.c
--- cargo-0.47.0/debian/libgit2/src/allocators/failalloc.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/failalloc.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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_calloc(size_t nelem, size_t elsize, const char *file, int line)
+{
+ GIT_UNUSED(nelem);
+ GIT_UNUSED(elsize);
+ GIT_UNUSED(file);
+ GIT_UNUSED(line);
+
+ return NULL;
+}
+
+char *git_failalloc_strdup(const char *str, const char *file, int line)
+{
+ GIT_UNUSED(str);
+ GIT_UNUSED(file);
+ GIT_UNUSED(line);
+
+ return NULL;
+}
+
+char *git_failalloc_strndup(const char *str, size_t n, const char *file, int line)
+{
+ GIT_UNUSED(str);
+ GIT_UNUSED(n);
+ GIT_UNUSED(file);
+ GIT_UNUSED(line);
+
+ return NULL;
+}
+
+char *git_failalloc_substrdup(const char *start, size_t n, const char *file, int line)
+{
+ GIT_UNUSED(start);
+ GIT_UNUSED(n);
+ 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_reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
+{
+ GIT_UNUSED(ptr);
+ GIT_UNUSED(nelem);
+ GIT_UNUSED(elsize);
+ GIT_UNUSED(file);
+ GIT_UNUSED(line);
+
+ return NULL;
+}
+
+void *git_failalloc_mallocarray(size_t nelem, size_t elsize, const char *file, int line)
+{
+ GIT_UNUSED(nelem);
+ GIT_UNUSED(elsize);
+ GIT_UNUSED(file);
+ GIT_UNUSED(line);
+
+ return NULL;
+}
+
+void git_failalloc_free(void *ptr)
+{
+ GIT_UNUSED(ptr);
+}
diff -Nru cargo-0.47.0/debian/libgit2/src/allocators/failalloc.h cargo-0.51.0/debian/libgit2/src/allocators/failalloc.h
--- cargo-0.47.0/debian/libgit2/src/allocators/failalloc.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/failalloc.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 "common.h"
+
+extern void *git_failalloc_malloc(size_t len, const char *file, int line);
+extern void *git_failalloc_calloc(size_t nelem, size_t elsize, const char *file, int line);
+extern char *git_failalloc_strdup(const char *str, const char *file, int line);
+extern char *git_failalloc_strndup(const char *str, size_t n, const char *file, int line);
+extern char *git_failalloc_substrdup(const char *start, size_t n, const char *file, int line);
+extern void *git_failalloc_realloc(void *ptr, size_t size, const char *file, int line);
+extern void *git_failalloc_reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line);
+extern void *git_failalloc_mallocarray(size_t nelem, size_t elsize, const char *file, int line);
+extern void git_failalloc_free(void *ptr);
+
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/allocators/win32_crtdbg.c cargo-0.51.0/debian/libgit2/src/allocators/win32_crtdbg.c
--- cargo-0.47.0/debian/libgit2/src/allocators/win32_crtdbg.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/win32_crtdbg.c 1970-01-01 00:00:00.000000000 +0000
@@ -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 "win32_crtdbg.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-
-#include "win32/w32_crtdbg_stacktrace.h"
-
-static void *crtdbg__malloc(size_t len, const char *file, int line)
-{
- void *ptr = _malloc_dbg(len, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
- if (!ptr) git_error_set_oom();
- return ptr;
-}
-
-static void *crtdbg__calloc(size_t nelem, size_t elsize, const char *file, int line)
-{
- void *ptr = _calloc_dbg(nelem, elsize, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
- if (!ptr) git_error_set_oom();
- return ptr;
-}
-
-static char *crtdbg__strdup(const char *str, const char *file, int line)
-{
- char *ptr = _strdup_dbg(str, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
- if (!ptr) git_error_set_oom();
- return ptr;
-}
-
-static char *crtdbg__strndup(const char *str, size_t n, const char *file, int line)
-{
- size_t length = 0, alloclength;
- char *ptr;
-
- length = p_strnlen(str, n);
-
- if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
- !(ptr = crtdbg__malloc(alloclength, file, line)))
- return NULL;
-
- if (length)
- memcpy(ptr, str, length);
-
- ptr[length] = '\0';
-
- return ptr;
-}
-
-static char *crtdbg__substrdup(const char *start, size_t n, const char *file, int line)
-{
- char *ptr;
- size_t alloclen;
-
- if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
- !(ptr = crtdbg__malloc(alloclen, file, line)))
- return NULL;
-
- memcpy(ptr, start, n);
- ptr[n] = '\0';
- return ptr;
-}
-
-static void *crtdbg__realloc(void *ptr, size_t size, const char *file, int line)
-{
- void *new_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, git_win32__crtdbg_stacktrace(1,file), line);
- if (!new_ptr) git_error_set_oom();
- return new_ptr;
-}
-
-static void *crtdbg__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
-{
- size_t newsize;
-
- if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize))
- return NULL;
-
- return crtdbg__realloc(ptr, newsize, file, line);
-}
-
-static void *crtdbg__mallocarray(size_t nelem, size_t elsize, const char *file, int line)
-{
- return crtdbg__reallocarray(NULL, nelem, elsize, file, line);
-}
-
-static void crtdbg__free(void *ptr)
-{
- free(ptr);
-}
-
-int git_win32_crtdbg_init_allocator(git_allocator *allocator)
-{
- allocator->gmalloc = crtdbg__malloc;
- allocator->gcalloc = crtdbg__calloc;
- allocator->gstrdup = crtdbg__strdup;
- allocator->gstrndup = crtdbg__strndup;
- allocator->gsubstrdup = crtdbg__substrdup;
- allocator->grealloc = crtdbg__realloc;
- allocator->greallocarray = crtdbg__reallocarray;
- allocator->gmallocarray = crtdbg__mallocarray;
- allocator->gfree = crtdbg__free;
- return 0;
-}
-
-#else
-
-int git_win32_crtdbg_init_allocator(git_allocator *allocator)
-{
- GIT_UNUSED(allocator);
- git_error_set(GIT_EINVALID, "crtdbg memory allocator not available");
- return -1;
-}
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/allocators/win32_crtdbg.h cargo-0.51.0/debian/libgit2/src/allocators/win32_crtdbg.h
--- cargo-0.47.0/debian/libgit2/src/allocators/win32_crtdbg.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/win32_crtdbg.h 1970-01-01 00:00:00.000000000 +0000
@@ -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_crtdbg_h
-#define INCLUDE_allocators_crtdbg_h
-
-#include "common.h"
-
-#include "alloc.h"
-
-int git_win32_crtdbg_init_allocator(git_allocator *allocator);
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/allocators/win32_leakcheck.c cargo-0.51.0/debian/libgit2/src/allocators/win32_leakcheck.c
--- cargo-0.47.0/debian/libgit2/src/allocators/win32_leakcheck.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/win32_leakcheck.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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_calloc(size_t nelem, size_t elsize, const char *file, int line)
+{
+ void *ptr = _calloc_dbg(nelem, elsize, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line);
+ if (!ptr) git_error_set_oom();
+ return ptr;
+}
+
+static char *leakcheck_strdup(const char *str, const char *file, int line)
+{
+ char *ptr = _strdup_dbg(str, _NORMAL_BLOCK, git_win32_leakcheck_stacktrace(1,file), line);
+ if (!ptr) git_error_set_oom();
+ return ptr;
+}
+
+static char *leakcheck_strndup(const char *str, size_t n, const char *file, int line)
+{
+ size_t length = 0, alloclength;
+ char *ptr;
+
+ length = p_strnlen(str, n);
+
+ if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
+ !(ptr = leakcheck_malloc(alloclength, file, line)))
+ return NULL;
+
+ if (length)
+ memcpy(ptr, str, length);
+
+ ptr[length] = '\0';
+
+ return ptr;
+}
+
+static char *leakcheck_substrdup(const char *start, size_t n, const char *file, int line)
+{
+ char *ptr;
+ size_t alloclen;
+
+ if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
+ !(ptr = leakcheck_malloc(alloclen, file, line)))
+ return NULL;
+
+ memcpy(ptr, start, n);
+ ptr[n] = '\0';
+ 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_reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
+{
+ size_t newsize;
+
+ if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize))
+ return NULL;
+
+ return leakcheck_realloc(ptr, newsize, file, line);
+}
+
+static void *leakcheck_mallocarray(size_t nelem, size_t elsize, const char *file, int line)
+{
+ return leakcheck_reallocarray(NULL, nelem, elsize, file, line);
+}
+
+static void leakcheck_free(void *ptr)
+{
+ free(ptr);
+}
+
+int git_win32_leakcheck_init_allocator(git_allocator *allocator)
+{
+ allocator->gmalloc = leakcheck_malloc;
+ allocator->gcalloc = leakcheck_calloc;
+ allocator->gstrdup = leakcheck_strdup;
+ allocator->gstrndup = leakcheck_strndup;
+ allocator->gsubstrdup = leakcheck_substrdup;
+ allocator->grealloc = leakcheck_realloc;
+ allocator->greallocarray = leakcheck_reallocarray;
+ allocator->gmallocarray = leakcheck_mallocarray;
+ 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 -Nru cargo-0.47.0/debian/libgit2/src/allocators/win32_leakcheck.h cargo-0.51.0/debian/libgit2/src/allocators/win32_leakcheck.h
--- cargo-0.47.0/debian/libgit2/src/allocators/win32_leakcheck.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/allocators/win32_leakcheck.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 "common.h"
+
+#include "alloc.h"
+
+int git_win32_leakcheck_init_allocator(git_allocator *allocator);
+
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/alloc.c cargo-0.51.0/debian/libgit2/src/alloc.c
--- cargo-0.47.0/debian/libgit2/src/alloc.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/alloc.c 2021-04-07 03:36:48.000000000 +0000
@@ -6,16 +6,29 @@
*/
#include "alloc.h"
+#include "runtime.h"
+#include "allocators/failalloc.h"
#include "allocators/stdalloc.h"
-#include "allocators/win32_crtdbg.h"
+#include "allocators/win32_leakcheck.h"
-git_allocator git__allocator;
+/* Fail any allocation until git_libgit2_init is called. */
+git_allocator git__allocator = {
+ git_failalloc_malloc,
+ git_failalloc_calloc,
+ git_failalloc_strdup,
+ git_failalloc_strndup,
+ git_failalloc_substrdup,
+ git_failalloc_realloc,
+ git_failalloc_reallocarray,
+ git_failalloc_mallocarray,
+ git_failalloc_free
+};
static int setup_default_allocator(void)
{
-#if defined(GIT_MSVC_CRTDBG)
- return git_win32_crtdbg_init_allocator(&git__allocator);
+#if defined(GIT_WIN32_LEAKCHECK)
+ return git_win32_leakcheck_init_allocator(&git__allocator);
#else
return git_stdalloc_init_allocator(&git__allocator);
#endif
@@ -24,10 +37,10 @@
int git_allocator_global_init(void)
{
/*
- * We don't want to overwrite any allocator which has been set before
- * the init function is called.
+ * We don't want to overwrite any allocator which has been set
+ * before the init function is called.
*/
- if (git__allocator.gmalloc != NULL)
+ if (git__allocator.gmalloc != git_failalloc_malloc)
return 0;
return setup_default_allocator();
diff -Nru cargo-0.47.0/debian/libgit2/src/annotated_commit.c cargo-0.51.0/debian/libgit2/src/annotated_commit.c
--- cargo-0.47.0/debian/libgit2/src/annotated_commit.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/annotated_commit.c 2021-04-07 03:36:48.000000000 +0000
@@ -26,7 +26,8 @@
git_annotated_commit *annotated_commit;
int error = 0;
- assert(out && commit);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(commit);
*out = NULL;
@@ -63,7 +64,9 @@
git_commit *commit = NULL;
int error = 0;
- assert(out && repo && id);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(id);
*out = NULL;
@@ -100,7 +103,9 @@
git_object *obj, *commit;
int error;
- assert(out && repo && revspec);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(revspec);
if ((error = git_revparse_single(&obj, repo, revspec)) < 0)
return error;
@@ -126,7 +131,9 @@
git_object *peeled;
int error = 0;
- assert(out && repo && ref);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(ref);
*out = NULL;
@@ -154,11 +161,12 @@
git_reference *head;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
- if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
+ if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
return -1;
error = git_annotated_commit_from_ref(out, repo, head);
@@ -174,7 +182,11 @@
const char *remote_url,
const git_oid *id)
{
- assert(repo && id && branch_name && remote_url);
+ 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;
@@ -192,14 +204,14 @@
const git_oid *git_annotated_commit_id(
const git_annotated_commit *annotated_commit)
{
- assert(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)
{
- assert(annotated_commit);
+ GIT_ASSERT_ARG_WITH_RETVAL(annotated_commit, NULL);
return annotated_commit->ref_name;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/apply.c cargo-0.51.0/debian/libgit2/src/apply.c
--- cargo-0.47.0/debian/libgit2/src/apply.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/apply.c 2021-04-07 03:36:48.000000000 +0000
@@ -5,8 +5,6 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "apply.h"
-
#include "git2/apply.h"
#include "git2/patch.h"
#include "git2/filter.h"
@@ -21,6 +19,7 @@
#include "zstream.h"
#include "reader.h"
#include "index.h"
+#include "apply.h"
typedef struct {
/* The lines that we allocate ourself are allocated out of the pool.
@@ -63,7 +62,11 @@
memset(out, 0x0, sizeof(patch_image));
- git_pool_init(&out->pool, sizeof(git_diff_line));
+ 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));
@@ -395,7 +398,11 @@
unsigned int mode = 0;
int error = 0;
- assert(contents_out && filename_out && mode_out && (source || !source_len) && patch);
+ 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));
@@ -620,7 +627,10 @@
size_t i;
int error = 0;
- assert(out && repo && preimage && diff);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(preimage);
+ GIT_ASSERT_ARG(diff);
*out = NULL;
@@ -768,6 +778,8 @@
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;
@@ -801,7 +813,8 @@
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
int error = GIT_EINVALID;
- assert(repo && diff);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(diff);
GIT_ERROR_CHECK_VERSION(
given_opts, GIT_APPLY_OPTIONS_VERSION, "git_apply_options");
@@ -825,7 +838,7 @@
error = git_reader_for_workdir(&pre_reader, repo, false);
break;
default:
- assert(false);
+ GIT_ASSERT(false);
}
if (error < 0)
@@ -865,7 +878,7 @@
error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
break;
default:
- assert(false);
+ GIT_ASSERT(false);
}
if (error < 0)
diff -Nru cargo-0.47.0/debian/libgit2/src/assert_safe.h cargo-0.51.0/debian/libgit2/src/assert_safe.h
--- cargo-0.47.0/debian/libgit2/src/assert_safe.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/assert_safe.h 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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)
+#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)
+
+#endif /* GIT_ASSERT_HARD */
+
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/attr.c cargo-0.51.0/debian/libgit2/src/attr.c
--- cargo-0.47.0/debian/libgit2/src/attr.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/attr.c 2021-04-07 03:36:48.000000000 +0000
@@ -58,7 +58,9 @@
git_attr_rule *rule;
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
- assert(value && repo && name);
+ GIT_ASSERT_ARG(value);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
*value = NULL;
@@ -123,7 +125,10 @@
if (!num_attr)
return 0;
- assert(values && repo && names);
+ GIT_ASSERT_ARG(values);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(pathname);
+ GIT_ASSERT_ARG(names);
if (git_repository_is_bare(repo))
dir_flag = GIT_DIR_FLAG_FALSE;
@@ -206,7 +211,8 @@
git_strmap *seen = NULL;
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
- assert(repo && callback);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(callback);
if (git_repository_is_bare(repo))
dir_flag = GIT_DIR_FLAG_FALSE;
@@ -378,6 +384,9 @@
git_attr_rule *macro = NULL;
git_pool *pool;
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
+
if ((error = git_attr_cache__init(repo)) < 0)
return error;
diff -Nru cargo-0.47.0/debian/libgit2/src/attrcache.c cargo-0.51.0/debian/libgit2/src/attrcache.c
--- cargo-0.47.0/debian/libgit2/src/attrcache.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/attrcache.c 2021-04-07 03:36:48.000000000 +0000
@@ -108,7 +108,7 @@
* Replace the existing value if another thread has
* created it in the meantime.
*/
- old = git__swap(entry->file[file->source], file);
+ old = git_atomic_swap(entry->file[file->source], file);
if (old) {
GIT_REFCOUNT_OWN(old, NULL);
@@ -132,7 +132,7 @@
return error;
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
- old = git__compare_and_swap(&entry->file[file->source], file, NULL);
+ old = git_atomic_compare_and_swap(&entry->file[file->source], file, NULL);
attr_cache_unlock(cache);
@@ -321,7 +321,7 @@
git_strmap_foreach_value(cache->files, entry, {
for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; ++i) {
- if ((file = git__swap(entry->file[i], NULL)) != NULL) {
+ if ((file = git_atomic_swap(entry->file[i], NULL)) != NULL) {
GIT_REFCOUNT_OWN(file, NULL);
git_attr_file__free(file);
}
@@ -391,12 +391,11 @@
* hashtable for attribute macros, and string pool
*/
if ((ret = git_strmap_new(&cache->files)) < 0 ||
- (ret = git_strmap_new(&cache->macros)) < 0)
+ (ret = git_strmap_new(&cache->macros)) < 0 ||
+ (ret = git_pool_init(&cache->pool, 1)) < 0)
goto cancel;
- git_pool_init(&cache->pool, 1);
-
- cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
+ cache = git_atomic_compare_and_swap(&repo->attrcache, NULL, cache);
if (cache)
goto cancel; /* raced with another thread, free this but no error */
@@ -418,7 +417,7 @@
/* 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__swap(repo->attrcache, NULL)) != NULL)
+ if (repo && (cache = git_atomic_swap(repo->attrcache, NULL)) != NULL)
attr_cache__free(cache);
return 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/attr_file.c cargo-0.51.0/debian/libgit2/src/attr_file.c
--- cargo-0.47.0/debian/libgit2/src/attr_file.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/attr_file.c 2021-04-07 03:36:48.000000000 +0000
@@ -41,16 +41,21 @@
if (git_mutex_init(&attrs->lock) < 0) {
git_error_set(GIT_ERROR_OS, "failed to initialize lock");
- git__free(attrs);
- return -1;
+ goto on_error;
}
- git_pool_init(&attrs->pool, 1);
+ if (git_pool_init(&attrs->pool, 1) < 0)
+ goto on_error;
+
GIT_REFCOUNT_INC(attrs);
attrs->entry = entry;
attrs->source = 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)
@@ -346,7 +351,9 @@
{
uint32_t h = 5381;
int c;
- assert(name);
+
+ GIT_ASSERT_ARG(name);
+
while ((c = (int)*name++) != 0)
h = ((h << 5) + h) + c;
return h;
@@ -655,7 +662,8 @@
int slash_count, allow_space;
bool escaped;
- assert(spec && base && *base);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(base && *base);
if (parse_optimized_patterns(spec, pool, *base))
return 0;
@@ -823,7 +831,7 @@
const char *scan = *base;
git_attr_assignment *assign = NULL;
- assert(assigns && !assigns->length);
+ GIT_ASSERT_ARG(assigns && !assigns->length);
git_vector_set_cmp(assigns, sort_by_hash_and_name);
@@ -949,10 +957,10 @@
int git_attr_session__init(git_attr_session *session, git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
memset(session, 0, sizeof(*session));
- session->key = git_atomic_inc(&repo->attr_session_key);
+ session->key = git_atomic32_inc(&repo->attr_session_key);
return 0;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/blame.c cargo-0.51.0/debian/libgit2/src/blame.c
--- cargo-0.47.0/debian/libgit2/src/blame.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/blame.c 2021-04-07 03:36:48.000000000 +0000
@@ -171,20 +171,21 @@
uint32_t git_blame_get_hunk_count(git_blame *blame)
{
- assert(blame);
+ GIT_ASSERT_ARG(blame);
return (uint32_t)blame->hunks.length;
}
const git_blame_hunk *git_blame_get_hunk_byindex(git_blame *blame, uint32_t index)
{
- assert(blame);
+ GIT_ASSERT_ARG_WITH_RETVAL(blame, NULL);
return (git_blame_hunk*)git_vector_get(&blame->hunks, index);
}
const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
{
size_t i, new_lineno = lineno;
- assert(blame);
+
+ GIT_ASSERT_ARG_WITH_RETVAL(blame, NULL);
if (!git_vector_bsearch2(&i, &blame->hunks, hunk_byfinalline_search_cmp, &new_lineno)) {
return git_blame_get_hunk_byindex(blame, (uint32_t)i);
@@ -388,7 +389,10 @@
git_blame_options normOptions = GIT_BLAME_OPTIONS_INIT;
git_blame *blame = NULL;
- assert(out && repo && path);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(path);
+
if ((error = normalize_options(&normOptions, options, repo)) < 0)
goto on_error;
@@ -509,7 +513,9 @@
diffopts.context_lines = 0;
- assert(out && reference && buffer && buffer_len);
+ 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);
@@ -538,7 +544,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/blame_git.c cargo-0.51.0/debian/libgit2/src/blame_git.c
--- cargo-0.47.0/debian/libgit2/src/blame_git.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/blame_git.c 2021-04-07 03:36:48.000000000 +0000
@@ -365,11 +365,14 @@
b->size -= trimmed - recovered;
}
-static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data)
+static int diff_hunks(mmfile_t file_a, mmfile_t file_b, void *cb_data, git_blame_options *options)
{
- xpparam_t xpp = {0};
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;
@@ -409,7 +412,7 @@
fill_origin_blob(parent, &file_p);
fill_origin_blob(target, &file_o);
- if (diff_hunks(file_p, file_o, &d) < 0)
+ 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 */
diff -Nru cargo-0.47.0/debian/libgit2/src/blob.c cargo-0.51.0/debian/libgit2/src/blob.c
--- cargo-0.47.0/debian/libgit2/src/blob.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/blob.c 2021-04-07 03:36:48.000000000 +0000
@@ -18,7 +18,8 @@
const void *git_blob_rawcontent(const git_blob *blob)
{
- assert(blob);
+ GIT_ASSERT_ARG_WITH_RETVAL(blob, NULL);
+
if (blob->raw)
return blob->data.raw.data;
else
@@ -27,7 +28,8 @@
git_object_size_t git_blob_rawsize(const git_blob *blob)
{
- assert(blob);
+ GIT_ASSERT_ARG(blob);
+
if (blob->raw)
return blob->data.raw.size;
else
@@ -53,7 +55,9 @@
int git_blob__parse_raw(void *_blob, const char *data, size_t size)
{
git_blob *blob = (git_blob *) _blob;
- assert(blob);
+
+ GIT_ASSERT_ARG(blob);
+
blob->raw = 1;
blob->data.raw.data = data;
blob->data.raw.size = size;
@@ -63,7 +67,9 @@
int git_blob__parse(void *_blob, git_odb_object *odb_obj)
{
git_blob *blob = (git_blob *) _blob;
- assert(blob);
+
+ GIT_ASSERT_ARG(blob);
+
git_cached_obj_incref((git_cached_obj *)odb_obj);
blob->raw = 0;
blob->data.odb = odb_obj;
@@ -77,7 +83,8 @@
git_odb *odb;
git_odb_stream *stream;
- assert(id && repo);
+ 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)
@@ -188,7 +195,7 @@
mode_t mode;
git_buf path = GIT_BUF_INIT;
- assert(hint_path || !try_load_filters);
+ GIT_ASSERT_ARG(hint_path || !try_load_filters);
if (!content_path) {
if (git_repository__ensure_not_bare(repo, "create blob from file") < 0)
@@ -331,7 +338,8 @@
git_buf path = GIT_BUF_INIT;
blob_writestream *stream;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
stream = git__calloc(1, sizeof(blob_writestream));
GIT_ERROR_CHECK_ALLOC(stream);
@@ -391,7 +399,7 @@
git_buf content = GIT_BUF_INIT;
git_object_size_t size;
- assert(blob);
+ GIT_ASSERT_ARG(blob);
size = git_blob_rawsize(blob);
@@ -411,13 +419,16 @@
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_filter_flag_t flags = GIT_FILTER_DEFAULT;
- assert(blob && path && out);
-
- git_buf_sanitize(out);
+ 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 (git_buf_sanitize(out) < 0)
+ return -1;
+
if (given_opts != NULL)
memcpy(&opts, given_opts, sizeof(git_blob_filter_options));
@@ -445,6 +456,7 @@
/* Deprecated functions */
+#ifndef GIT_DEPRECATE_HARD
int git_blob_create_frombuffer(
git_oid *id, git_repository *repo, const void *buffer, size_t len)
{
@@ -491,3 +503,4 @@
return git_blob_filter(out, blob, path, &opts);
}
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/branch.c cargo-0.51.0/debian/libgit2/src/branch.c
--- cargo-0.47.0/debian/libgit2/src/branch.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/branch.c 2021-04-07 03:36:48.000000000 +0000
@@ -67,8 +67,10 @@
int error = -1;
int bare = git_repository_is_bare(repository);
- assert(branch_name && commit && ref_out);
- assert(git_object_owner((const git_object *)commit) == repository);
+ GIT_ASSERT_ARG(branch_name);
+ GIT_ASSERT_ARG(commit);
+ GIT_ASSERT_ARG(ref_out);
+ GIT_ASSERT_ARG(git_commit_owner(commit) == repository);
if (!git__strcmp(branch_name, "HEAD")) {
git_error_set(GIT_ERROR_REFERENCE, "'HEAD' is not a valid branch name");
@@ -134,39 +136,39 @@
repository, branch_name, commit->commit, commit->description, force);
}
-static int branch_equals(git_repository *repo, const char *path, void *payload)
+static int branch_is_checked_out(git_repository *worktree, void *payload)
{
git_reference *branch = (git_reference *) payload;
git_reference *head = NULL;
- int equal = 0;
+ int error;
- if (git_reference__read_head(&head, repo, path) < 0 ||
- git_reference_type(head) != GIT_REFERENCE_SYMBOLIC)
- goto done;
+ if (git_repository_is_bare(worktree))
+ return 0;
- equal = !git__strcmp(head->target.symbolic, branch->name);
+ if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0) {
+ if (error == GIT_ENOTFOUND)
+ error = 0;
+ goto out;
+ }
-done:
+ if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC)
+ goto out;
+
+ error = !git__strcmp(head->target.symbolic, branch->name);
+
+out:
git_reference_free(head);
- return equal;
+ return error;
}
int git_branch_is_checked_out(const git_reference *branch)
{
- git_repository *repo;
- int flags = 0;
-
- assert(branch);
+ GIT_ASSERT_ARG(branch);
if (!git_reference_is_branch(branch))
return 0;
-
- repo = git_reference_owner(branch);
-
- if (git_repository_is_bare(repo))
- flags |= GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO;
-
- return git_repository_foreach_head(repo, branch_equals, flags, (void *) branch) == 1;
+ return git_repository_foreach_worktree(git_reference_owner(branch),
+ branch_is_checked_out, (void *)branch) == 1;
}
int git_branch_delete(git_reference *branch)
@@ -175,7 +177,7 @@
git_buf config_section = GIT_BUF_INIT;
int error = -1;
- assert(branch);
+ 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.",
@@ -290,7 +292,8 @@
log_message = GIT_BUF_INIT;
int error;
- assert(branch && new_branch_name);
+ 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));
@@ -335,7 +338,10 @@
git_branch_t branch_type)
{
int error = -1;
- assert(ref_out && repo && branch_name);
+
+ GIT_ASSERT_ARG(ref_out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(branch_name);
switch (branch_type) {
case GIT_BRANCH_LOCAL:
@@ -348,7 +354,7 @@
error = retrieve_branch_reference(ref_out, repo, branch_name, true);
break;
default:
- assert(false);
+ GIT_ASSERT(false);
}
return error;
}
@@ -359,7 +365,8 @@
{
const char *branch_name;
- assert(out && ref);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ref);
branch_name = ref->name;
@@ -407,9 +414,11 @@
const git_refspec *refspec;
git_config *config;
- assert(out && refname);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(refname);
- git_buf_sanitize(out);
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (!git_reference__is_branch(refname))
return not_a_local_branch(refname);
@@ -470,9 +479,8 @@
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
- git_buf_sanitize(buf);
-
- if ((error = retrieve_upstream_configuration(buf, cfg, refname, "branch.%s.remote")) < 0)
+ if ((error = git_buf_sanitize(buf)) < 0 ||
+ (error = retrieve_upstream_configuration(buf, cfg, refname, "branch.%s.remote")) < 0)
return error;
if (git_buf_len(buf) == 0) {
@@ -493,9 +501,12 @@
int error = 0;
char *remote_name = NULL;
- assert(buf && repo && refname);
+ GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refname);
- git_buf_sanitize(buf);
+ if ((error = git_buf_sanitize(buf)) < 0)
+ return error;
/* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) {
@@ -548,7 +559,7 @@
if (error < 0)
git_buf_dispose(buf);
- git_strarray_free(&remote_list);
+ git_strarray_dispose(&remote_list);
return error;
}
@@ -704,7 +715,7 @@
bool is_same = false;
int error;
- assert(branch);
+ GIT_ASSERT_ARG(branch);
if (!git_reference_is_branch(branch))
return false;
@@ -725,3 +736,32 @@
return is_same;
}
+
+int git_branch_name_is_valid(int *valid, const char *name)
+{
+ git_buf ref_name = GIT_BUF_INIT;
+ int error = 0;
+
+ GIT_ASSERT(valid);
+
+ *valid = 0;
+
+ /*
+ * 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
+ */
+ if (!name || name[0] == '-' || !git__strcmp(name, "HEAD"))
+ goto done;
+
+ if ((error = git_buf_puts(&ref_name, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_buf_puts(&ref_name, name)) < 0)
+ goto done;
+
+ error = git_reference_name_is_valid(valid, ref_name.ptr);
+
+done:
+ git_buf_dispose(&ref_name);
+ return error;
+}
diff -Nru cargo-0.47.0/debian/libgit2/src/buffer.c cargo-0.51.0/debian/libgit2/src/buffer.c
--- cargo-0.47.0/debian/libgit2/src/buffer.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/buffer.c 2021-04-07 03:36:48.000000000 +0000
@@ -133,18 +133,24 @@
git_buf_init(buf, 0);
}
+#ifndef GIT_DEPRECATE_HARD
void git_buf_free(git_buf *buf)
{
git_buf_dispose(buf);
}
+#endif
-void git_buf_sanitize(git_buf *buf)
+int git_buf_sanitize(git_buf *buf)
{
if (buf->ptr == NULL) {
- assert(buf->size == 0 && buf->asize == 0);
+ GIT_ASSERT_ARG(buf->size == 0 && buf->asize == 0);
+
buf->ptr = git_buf__initbuf;
- } else if (buf->asize > buf->size)
+ } else if (buf->asize > buf->size) {
buf->ptr[buf->size] = '\0';
+ }
+
+ return 0;
}
void git_buf_clear(git_buf *buf)
@@ -223,7 +229,7 @@
if (len) {
size_t new_size;
- assert(data);
+ GIT_ASSERT_ARG(data);
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, len);
GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
@@ -237,7 +243,8 @@
int git_buf_puts(git_buf *buf, const char *string)
{
- assert(string);
+ GIT_ASSERT_ARG(string);
+
return git_buf_put(buf, string, strlen(string));
}
@@ -317,7 +324,7 @@
return -1;
}
- assert(len % 4 == 0);
+ 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);
@@ -363,7 +370,7 @@
for (i = 24; i >= 0; i -= 8) {
uint8_t ch = *data++;
- acc |= ch << i;
+ acc |= (uint32_t)ch << i;
if (--len == 0)
break;
@@ -549,22 +556,26 @@
return r;
}
-void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
+int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf)
{
size_t copylen;
- assert(data && datasize && buf);
+ GIT_ASSERT_ARG(data);
+ GIT_ASSERT_ARG(datasize);
+ GIT_ASSERT_ARG(buf);
data[0] = '\0';
if (buf->size == 0 || buf->asize <= 0)
- return;
+ return 0;
copylen = buf->size;
if (copylen > datasize - 1)
copylen = datasize - 1;
memmove(data, buf->ptr, copylen);
data[copylen] = '\0';
+
+ return 0;
}
void git_buf_consume_bytes(git_buf *buf, size_t len)
@@ -757,7 +768,8 @@
ssize_t offset_a = -1;
/* not safe to have str_b point internally to the buffer */
- assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
+ 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) {
@@ -767,7 +779,7 @@
}
/* str_a could be part of the buffer */
- if (str_a >= buf->ptr && str_a < buf->ptr + buf->size)
+ 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);
@@ -807,9 +819,9 @@
char *tgt;
/* for this function, disallow pointers into the existing buffer */
- assert(str_a < buf->ptr || str_a >= buf->ptr + buf->size);
- assert(str_b < buf->ptr || str_b >= buf->ptr + buf->size);
- assert(str_c < buf->ptr || str_c >= buf->ptr + buf->size);
+ 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) {
@@ -882,7 +894,9 @@
char *splice_loc;
size_t new_size, alloc_size;
- assert(buf && where <= buf->size && nb_to_remove <= buf->size - where);
+ GIT_ASSERT(buf);
+ GIT_ASSERT(where <= buf->size);
+ GIT_ASSERT(nb_to_remove <= buf->size - where);
splice_loc = buf->ptr + where;
diff -Nru cargo-0.47.0/debian/libgit2/src/buffer.h cargo-0.51.0/debian/libgit2/src/buffer.h
--- cargo-0.47.0/debian/libgit2/src/buffer.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/buffer.h 2021-04-07 03:36:48.000000000 +0000
@@ -69,7 +69,7 @@
* git_buf__initbuf. If a buffer with a non-NULL ptr is passed in, this method
* assures that the buffer is '\0'-terminated.
*/
-extern void git_buf_sanitize(git_buf *buf);
+extern int git_buf_sanitize(git_buf *buf);
extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
extern char *git_buf_detach(git_buf *buf);
@@ -145,7 +145,7 @@
return buf->size;
}
-void git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
+int git_buf_copy_cstr(char *data, size_t datasize, const git_buf *buf);
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
diff -Nru cargo-0.47.0/debian/libgit2/src/buf_text.c cargo-0.51.0/debian/libgit2/src/buf_text.c
--- cargo-0.47.0/debian/libgit2/src/buf_text.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/buf_text.c 2021-04-07 03:36:48.000000000 +0000
@@ -69,7 +69,7 @@
size_t new_size;
char *out;
- assert(tgt != src);
+ GIT_ASSERT(tgt != src);
if (!next)
return git_buf_set(tgt, src->ptr, src->size);
@@ -116,7 +116,7 @@
const char *next = memchr(scan, '\n', src->size);
size_t alloclen;
- assert(tgt != src);
+ GIT_ASSERT(tgt != src);
if (!next)
return git_buf_set(tgt, src->ptr, src->size);
diff -Nru cargo-0.47.0/debian/libgit2/src/cache.c cargo-0.51.0/debian/libgit2/src/cache.c
--- cargo-0.47.0/debian/libgit2/src/cache.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/cache.c 2021-04-07 03:36:48.000000000 +0000
@@ -9,7 +9,7 @@
#include "repository.h"
#include "commit.h"
-#include "thread-utils.h"
+#include "thread.h"
#include "util.h"
#include "odb.h"
#include "object.h"
@@ -41,27 +41,6 @@
return 0;
}
-void git_cache_dump_stats(git_cache *cache)
-{
- git_cached_obj *object;
-
- if (git_cache_size(cache) == 0)
- return;
-
- printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n",
- cache, git_cache_size(cache), cache->used_memory);
-
- git_oidmap_foreach_value(cache->map, object, {
- char oid_str[9];
- printf(" %s%c %s (%"PRIuZ")\n",
- git_object_type2string(object->type),
- object->flags == GIT_CACHE_STORE_PARSED ? '*' : ' ',
- git_oid_tostr(oid_str, sizeof(oid_str), &object->oid),
- object->size
- );
- });
-}
-
int git_cache_init(git_cache *cache)
{
memset(cache, 0, sizeof(*cache));
@@ -189,7 +168,7 @@
return entry;
/* soften the load on the cache */
- if (git_cache__current_storage.val > git_cache__max_storage)
+ if (git_atomic_ssize_get(&git_cache__current_storage) > git_cache__max_storage)
cache_evict_entries(cache);
/* not found */
@@ -256,7 +235,7 @@
{
git_cached_obj *obj = _obj;
- if (git_atomic_dec(&obj->refcount) == 0) {
+ if (git_atomic32_dec(&obj->refcount) == 0) {
switch (obj->flags) {
case GIT_CACHE_STORE_RAW:
git_odb_object__free(_obj);
diff -Nru cargo-0.47.0/debian/libgit2/src/cache.h cargo-0.51.0/debian/libgit2/src/cache.h
--- cargo-0.47.0/debian/libgit2/src/cache.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/cache.h 2021-04-07 03:36:48.000000000 +0000
@@ -13,7 +13,7 @@
#include "git2/oid.h"
#include "git2/odb.h"
-#include "thread-utils.h"
+#include "thread.h"
#include "oidmap.h"
enum {
@@ -23,11 +23,11 @@
};
typedef struct {
- git_oid oid;
- int16_t type; /* git_object_t value */
- uint16_t flags; /* GIT_CACHE_STORE value */
- size_t size;
- git_atomic refcount;
+ 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;
typedef struct {
@@ -61,7 +61,7 @@
GIT_INLINE(void) git_cached_obj_incref(void *_obj)
{
git_cached_obj *obj = _obj;
- git_atomic_inc(&obj->refcount);
+ git_atomic32_inc(&obj->refcount);
}
void git_cached_obj_decref(void *_obj);
diff -Nru cargo-0.47.0/debian/libgit2/src/checkout.c cargo-0.51.0/debian/libgit2/src/checkout.c
--- cargo-0.47.0/debian/libgit2/src/checkout.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/checkout.c 2021-04-07 03:36:48.000000000 +0000
@@ -44,7 +44,6 @@
CHECKOUT_ACTION__REMOVE_CONFLICT = 16,
CHECKOUT_ACTION__UPDATE_CONFLICT = 32,
CHECKOUT_ACTION__MAX = 32,
- CHECKOUT_ACTION__DEFER_REMOVE = 64,
CHECKOUT_ACTION__REMOVE_AND_UPDATE =
(CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE),
};
@@ -196,7 +195,7 @@
}
if (git_submodule_status(&sm_status, data->repo, wditem->path, GIT_SUBMODULE_IGNORE_UNSPECIFIED) < 0 ||
- GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
+ GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
rval = true;
else if ((sm_oid = git_submodule_wd_id(sm)) == NULL)
rval = false;
@@ -217,9 +216,10 @@
ie = git_index_get_bypath(data->index, wditem->path, 0);
if (ie != NULL &&
- git_index_time_eq(&wditem->mtime, &ie->mtime) &&
- wditem->file_size == ie->file_size &&
- !is_filemode_changed(wditem->mode, ie->mode, data->respect_filemode)) {
+ !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) ||
@@ -273,9 +273,8 @@
/* 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;
+ GIT_PERMS_IS_EXEC(wd->mode) != GIT_PERMS_IS_EXEC(delta->new_file.mode))
+ *action |= CHECKOUT_ACTION__REMOVE;
notify = GIT_CHECKOUT_NOTIFY_UPDATED;
}
@@ -371,8 +370,13 @@
if (!git_pathspec__match(
pathspec, wd->path,
(data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0,
- git_iterator_ignore_case(workdir), NULL, NULL))
- return git_iterator_advance(wditem, workdir);
+ 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) {
@@ -794,13 +798,13 @@
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->ours, cb->theirs)) == 0)
diff = checkout_idxentry_cmp(ca->theirs, cb->theirs);
return diff;
}
-int checkout_conflictdata_empty(
+static int checkout_conflictdata_empty(
const git_vector *conflicts, size_t idx, void *payload)
{
checkout_conflictdata *conflict;
@@ -1173,7 +1177,7 @@
/* Find d/f conflicts */
git_vector_foreach(&data->update_conflicts, i, conflict) {
if ((conflict->ours && conflict->theirs) ||
- (!conflict->ours && !conflict->theirs))
+ (!conflict->ours && !conflict->theirs))
continue;
path = conflict->ours ?
@@ -1222,8 +1226,8 @@
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)
+ (error = checkout_conflicts_coalesce_renames(data)) < 0 ||
+ (error = checkout_conflicts_mark_directoryfile(data)) < 0)
goto done;
done:
@@ -1239,7 +1243,7 @@
checkout_data *data = payload;
const char *name;
- assert(ancestor || ours || theirs);
+ GIT_ASSERT_ARG(ancestor || ours || theirs);
if (ancestor)
name = git__strdup(ancestor->path);
@@ -1304,14 +1308,15 @@
size_t i, *counts = NULL;
uint32_t *actions = NULL;
- git_pool_init(&pathpool, 1);
+ if (git_pool_init(&pathpool, 1) < 0)
+ return -1;
if (data->opts.paths.count > 0 &&
- git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
+ git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
return -1;
if ((error = git_iterator_current(&wditem, workdir)) < 0 &&
- error != GIT_ITEROVER)
+ error != GIT_ITEROVER)
goto fail;
deltas = &data->diff->deltas;
@@ -1350,8 +1355,7 @@
counts[CHECKOUT_ACTION__REMOVE] += data->removes.length;
if (counts[CHECKOUT_ACTION__CONFLICT] > 0 &&
- (data->strategy & GIT_CHECKOUT_ALLOW_CONFLICTS) == 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 ?
@@ -1362,7 +1366,7 @@
if ((error = checkout_get_remove_conflicts(data, workdir, &pathspec)) < 0 ||
- (error = checkout_get_update_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);
@@ -1483,7 +1487,9 @@
static int checkout_stream_close(git_writestream *s)
{
struct checkout_stream *stream = (struct checkout_stream *)s;
- assert(stream && stream->open);
+
+ GIT_ASSERT_ARG(stream);
+ GIT_ASSERT_ARG(stream->open);
stream->open = 0;
return p_close(stream->fd);
@@ -1550,7 +1556,7 @@
error = git_filter_list_stream_blob(fl, blob, &writer.base);
- assert(writer.open == 0);
+ GIT_ASSERT(writer.open == 0);
git_filter_list_free(fl);
@@ -1853,26 +1859,6 @@
return 0;
}
-static int checkout_deferred_remove(git_repository *repo, const char *path)
-{
-#if 0
- int error = git_futils_rmdir_r(
- path, data->opts.target_directory, GIT_RMDIR_EMPTY_PARENTS);
-
- if (error == GIT_ENOTFOUND) {
- error = 0;
- git_error_clear();
- }
-
- return error;
-#else
- GIT_UNUSED(repo);
- GIT_UNUSED(path);
- assert(false);
- return 0;
-#endif
-}
-
static int checkout_create_the_new(
unsigned int *actions,
checkout_data *data)
@@ -1882,15 +1868,6 @@
size_t i;
git_vector_foreach(&data->diff->deltas, i, delta) {
- if (actions[i] & CHECKOUT_ACTION__DEFER_REMOVE) {
- /* this had a blocker directory that should only be removed iff
- * all of the contents of the directory were safely removed
- */
- if ((error = checkout_deferred_remove(
- data->repo, delta->old_file.path)) < 0)
- return error;
- }
-
if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && !S_ISLNK(delta->new_file.mode)) {
if ((error = checkout_blob(data, &delta->new_file)) < 0)
return error;
@@ -1915,20 +1892,10 @@
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__DEFER_REMOVE) {
- /* this has a blocker directory that should only be removed iff
- * all of the contents of the directory were safely removed
- */
- if ((error = checkout_deferred_remove(
- data->repo, delta->old_file.path)) < 0)
- return error;
- }
-
if (actions[i] & CHECKOUT_ACTION__UPDATE_SUBMODULE) {
int error = checkout_submodule(data, &delta->new_file);
if (error < 0)
@@ -2011,7 +1978,7 @@
struct stat st;
int error;
- assert (side == conflict->ours || side == conflict->theirs);
+ GIT_ASSERT(side == conflict->ours || side == conflict->theirs);
if (checkout_target_fullpath(&fullpath, data, side->path) < 0)
return -1;
@@ -2520,9 +2487,8 @@
git_config_entry_free(conflict_style);
}
- git_pool_init(&data->pool, 1);
-
- if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
+ 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_buf_puts(&data->target_path, data->opts.target_directory)) < 0 ||
@@ -2544,6 +2510,17 @@
#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,
@@ -2586,6 +2563,8 @@
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,
@@ -2596,10 +2575,8 @@
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
baseline_opts.start = data.pfx;
baseline_opts.end = data.pfx;
- if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
- baseline_opts.pathlist.count = opts->paths.count;
- baseline_opts.pathlist.strings = opts->paths.strings;
- }
+
+ setup_pathspecs(&baseline_opts, opts);
if (data.opts.baseline_index) {
if ((error = git_iterator_for_index(
@@ -2613,7 +2590,7 @@
}
/* Should not have case insensitivity mismatch */
- assert(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline));
+ 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.
@@ -2664,7 +2641,7 @@
(error = checkout_extensions_update_index(&data)) < 0)
goto cleanup;
- assert(data.completed_steps == data.total_steps);
+ GIT_ASSERT(data.completed_steps == data.total_steps);
if (data.opts.perfdata_cb)
data.opts.perfdata_cb(&data.perfdata, data.opts.perfdata_payload);
@@ -2689,6 +2666,7 @@
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;
@@ -2716,7 +2694,9 @@
return error;
GIT_REFCOUNT_INC(index);
- if (!(error = git_iterator_for_index(&index_i, repo, index, NULL)))
+ 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)
@@ -2773,10 +2753,7 @@
if ((error = git_repository_index(&index, repo)) < 0)
return error;
- if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
- iter_opts.pathlist.count = opts->paths.count;
- iter_opts.pathlist.strings = opts->paths.strings;
- }
+ setup_pathspecs(&iter_opts, opts);
if (!(error = git_iterator_for_tree(&tree_i, tree, &iter_opts)))
error = git_checkout_iterator(tree_i, index, opts);
@@ -2792,7 +2769,8 @@
git_repository *repo,
const git_checkout_options *opts)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
+
return git_checkout_tree(repo, NULL, opts);
}
@@ -2803,7 +2781,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/cherrypick.c cargo-0.51.0/debian/libgit2/src/cherrypick.c
--- cargo-0.47.0/debian/libgit2/src/cherrypick.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/cherrypick.c 2021-04-07 03:36:48.000000000 +0000
@@ -126,7 +126,10 @@
git_tree *parent_tree = NULL, *our_tree = NULL, *cherrypick_tree = NULL;
int parent = 0, error = 0;
- assert(out && repo && cherrypick_commit && our_commit);
+ 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)
@@ -177,7 +180,8 @@
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error = 0;
- assert(repo && commit);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commit);
GIT_ERROR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options");
@@ -229,8 +233,10 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/clone.c cargo-0.51.0/debian/libgit2/src/clone.c
--- cargo-0.47.0/debian/libgit2/src/clone.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/clone.c 2021-04-07 03:36:48.000000000 +0000
@@ -137,6 +137,80 @@
return error;
}
+static int update_head_to_default(git_repository *repo)
+{
+ git_buf initialbranch = GIT_BUF_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_buf_dispose(&initialbranch);
+ return error;
+}
+
+static int update_remote_head(
+ git_repository *repo,
+ git_remote *remote,
+ git_buf *target,
+ const char *reflog_message)
+{
+ git_refspec *refspec;
+ git_reference *remote_head = NULL;
+ git_buf remote_head_name = GIT_BUF_INIT;
+ git_buf remote_branch_name = GIT_BUF_INIT;
+ int error;
+
+ /* Determine the remote tracking ref name from the local branch */
+ refspec = git_remote__matching_refspec(remote, git_buf_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_buf_cstr(target))) < 0)
+ goto cleanup;
+
+ if ((error = git_buf_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_buf_cstr(&remote_head_name),
+ git_buf_cstr(&remote_branch_name),
+ true,
+ reflog_message);
+
+cleanup:
+ git_reference_free(remote_head);
+ git_buf_dispose(&remote_branch_name);
+ git_buf_dispose(&remote_head_name);
+ return error;
+}
+
static int update_head_to_remote(
git_repository *repo,
git_remote *remote,
@@ -144,10 +218,8 @@
{
int error = 0;
size_t refs_len;
- git_refspec *refspec;
const git_remote_head *remote_head, **refs;
const git_oid *remote_head_id;
- git_buf remote_master_name = GIT_BUF_INIT;
git_buf branch = GIT_BUF_INIT;
if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
@@ -155,12 +227,11 @@
/* We cloned an empty repository or one with an unborn HEAD */
if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_FILE))
- return setup_tracking_config(
- repo, "master", GIT_REMOTE_ORIGIN, GIT_REFS_HEADS_MASTER_FILE);
+ return update_head_to_default(repo);
/* We know we have HEAD, let's see where it points */
remote_head = refs[0];
- assert(remote_head);
+ GIT_ASSERT(remote_head);
remote_head_id = &remote_head->oid;
@@ -171,19 +242,7 @@
goto cleanup;
}
- refspec = git_remote__matching_refspec(remote, git_buf_cstr(&branch));
-
- 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;
- }
-
- /* Determine the remote tracking reference name from the local master */
- if ((error = git_refspec_transform(
- &remote_master_name,
- refspec,
- git_buf_cstr(&branch))) < 0)
+ if ((error = update_remote_head(repo, remote, &branch, reflog_message)) < 0)
goto cleanup;
error = update_head_to_new_branch(
@@ -193,7 +252,6 @@
reflog_message);
cleanup:
- git_buf_dispose(&remote_master_name);
git_buf_dispose(&branch);
return error;
@@ -209,7 +267,8 @@
git_buf remote_branch_name = GIT_BUF_INIT;
git_reference* remote_ref = NULL;
- assert(remote_name && branch);
+ GIT_ASSERT_ARG(remote_name);
+ GIT_ASSERT_ARG(branch);
if ((retcode = git_buf_printf(&remote_branch_name, GIT_REFS_REMOTES_DIR "%s/%s",
remote_name, branch)) < 0 )
@@ -327,7 +386,8 @@
git_fetch_options fetch_opts;
git_remote *remote;
- assert(repo && _remote);
+ 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");
@@ -394,7 +454,9 @@
uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES;
git_repository_create_cb repository_cb;
- assert(out && url && local_path);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(url);
+ GIT_ASSERT_ARG(local_path);
if (_options)
memcpy(&options, _options, sizeof(git_clone_options));
@@ -479,10 +541,12 @@
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
static bool can_link(const char *src, const char *dst, int link)
{
@@ -515,7 +579,8 @@
git_buf src_odb = GIT_BUF_INIT, dst_odb = GIT_BUF_INIT, src_path = GIT_BUF_INIT;
git_buf reflog_message = GIT_BUF_INIT;
- assert(repo && remote);
+ 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");
diff -Nru cargo-0.47.0/debian/libgit2/src/CMakeLists.txt cargo-0.51.0/debian/libgit2/src/CMakeLists.txt
--- cargo-0.47.0/debian/libgit2/src/CMakeLists.txt 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/CMakeLists.txt 2021-04-07 03:36:48.000000000 +0000
@@ -1,3 +1,6 @@
+add_library(git2internal OBJECT)
+set_target_properties(git2internal PROPERTIES C_STANDARD 90)
+
IF(DEBUG_POOL)
SET(GIT_DEBUG_POOL 1)
ENDIF()
@@ -21,6 +24,8 @@
SET(LIBGIT2_SYSTEM_INCLUDES "")
SET(LIBGIT2_LIBS "")
+enable_warnings(missing-declarations)
+
# Enable tracing
IF(ENABLE_TRACE)
SET(GIT_TRACE 1)
@@ -36,19 +41,19 @@
"void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
"" "stdlib.h" HAVE_QSORT_R_BSD)
IF (HAVE_QSORT_R_BSD)
- ADD_DEFINITIONS(-DHAVE_QSORT_R_BSD)
+ target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_BSD)
ENDIF()
CHECK_PROTOTYPE_DEFINITION(qsort_r
"void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
"" "stdlib.h" HAVE_QSORT_R_GNU)
IF (HAVE_QSORT_R_GNU)
- ADD_DEFINITIONS(-DHAVE_QSORT_R_GNU)
+ target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_GNU)
ENDIF()
CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S)
IF (HAVE_QSORT_S)
- ADD_DEFINITIONS(-DHAVE_QSORT_S)
+ target_compile_definitions(git2internal PRIVATE HAVE_QSORT_S)
ENDIF ()
# Find required dependencies
@@ -76,12 +81,15 @@
ADD_FEATURE_INFO(threadsafe THREADSAFE "threadsafe support")
-IF (WIN32 AND EMBED_SSH_PATH)
- FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
- LIST(APPEND LIBGIT2_SYSTEM_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\"")
- SET(GIT_SSH 1)
-ENDIF()
+if(WIN32 AND EMBED_SSH_PATH)
+ file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
+ list(SORT SRC_SSH)
+ target_sources(git2internal PRIVATE ${SRC_SSH})
+
+ list(APPEND LIBGIT2_SYSTEM_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\"")
+ set(GIT_SSH 1)
+endif()
IF (WIN32 AND WINHTTP)
SET(GIT_WINHTTP 1)
@@ -101,8 +109,9 @@
LIST(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
ENDIF()
-Include(SelectHTTPSBackend)
-Include(SelectHashes)
+include(SelectHTTPSBackend)
+include(SelectHashes)
+target_sources(git2internal PRIVATE ${SRC_SHA1})
# Specify regular expression implementation
FIND_PACKAGE(PCRE)
@@ -264,36 +273,43 @@
SET(GIT_USE_STAT_MTIME_NSEC 1)
ENDIF()
-ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
+target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64)
# Collect sourcefiles
-FILE(GLOB SRC_H
+file(GLOB SRC_H
"${libgit2_SOURCE_DIR}/include/git2.h"
"${libgit2_SOURCE_DIR}/include/git2/*.h"
"${libgit2_SOURCE_DIR}/include/git2/sys/*.h")
+list(SORT SRC_H)
+target_sources(git2internal PRIVATE ${SRC_H})
# On Windows use specific platform sources
-IF (WIN32 AND NOT CYGWIN)
- IF(MSVC)
- SET(WIN_RC "win32/git2.rc")
- ENDIF()
+if(WIN32 AND NOT CYGWIN)
+ SET(WIN_RC "win32/git2.rc")
- FILE(GLOB SRC_OS win32/*.c win32/*.h)
-ELSEIF (AMIGA)
- ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
-ELSE()
- FILE(GLOB SRC_OS unix/*.c unix/*.h)
-ENDIF()
+ file(GLOB SRC_OS win32/*.c win32/*.h)
+ list(SORT SRC_OS)
+ target_sources(git2internal PRIVATE ${SRC_OS})
+elseif(AMIGA)
+ target_compile_definitions(git2internal PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
+else()
+ file(GLOB SRC_OS unix/*.c unix/*.h)
+ list(SORT SRC_OS)
+ target_sources(git2internal PRIVATE ${SRC_OS})
+endif()
IF (USE_LEAK_CHECKER STREQUAL "valgrind")
- ADD_DEFINITIONS(-DVALGRIND)
+ target_compile_definitions(git2internal PRIVATE VALGRIND)
ENDIF()
-FILE(GLOB SRC_GIT2 *.c *.h
+file(GLOB SRC_GIT2 *.c *.h
allocators/*.c allocators/*.h
streams/*.c streams/*.h
transports/*.c transports/*.h
xdiff/*.c xdiff/*.h)
+list(SORT SRC_GIT2)
+target_sources(git2internal PRIVATE ${SRC_GIT2})
+
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)
@@ -319,10 +335,6 @@
CONFIGURE_FILE(features.h.in git2/sys/features.h)
-SET(LIBGIT2_SOURCES ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
-
-ADD_LIBRARY(git2internal OBJECT ${LIBGIT2_SOURCES})
-SET_TARGET_PROPERTIES(git2internal PROPERTIES C_STANDARD 90)
IDE_SPLIT_SOURCES(git2internal)
LIST(APPEND LIBGIT2_OBJECTS $)
@@ -358,19 +370,19 @@
IDE_SPLIT_SOURCES(git2)
-IF (SONAME)
- SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
- SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION})
- IF (LIBGIT2_FILENAME)
- ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
- SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
- ELSEIF (DEFINED LIBGIT2_PREFIX)
- SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
- ENDIF()
-ENDIF()
+if(SONAME)
+ set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION})
+ set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
+ if(LIBGIT2_FILENAME)
+ target_compile_definitions(git2internal PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
+ set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
+ elseif(DEFINED LIBGIT2_PREFIX)
+ set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
+ endif()
+endif()
PKG_BUILD_CONFIG(NAME libgit2
- VERSION ${LIBGIT2_VERSION_STRING}
+ VERSION ${libgit2_VERSION}
DESCRIPTION "The git library, take 2"
LIBS_SELF git2
PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
diff -Nru cargo-0.47.0/debian/libgit2/src/commit.c cargo-0.51.0/debian/libgit2/src/commit.c
--- cargo-0.47.0/debian/libgit2/src/commit.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/commit.c 2021-04-07 03:36:48.000000000 +0000
@@ -53,7 +53,8 @@
size_t i = 0;
const git_oid *parent;
- assert(out && tree);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(tree);
git_oid__writebuf(out, "tree ", tree);
@@ -229,7 +230,8 @@
int error = 0;
commit_parent_varargs data;
- assert(tree && git_tree_owner(tree) == repo);
+ GIT_ASSERT_ARG(tree);
+ GIT_ASSERT_ARG(git_tree_owner(tree) == repo);
data.total = parent_count;
va_start(data.args, parent_count);
@@ -306,7 +308,8 @@
{
commit_parent_data data = { parent_count, parents, repo };
- assert(tree && git_tree_owner(tree) == repo);
+ GIT_ASSERT_ARG(tree);
+ GIT_ASSERT_ARG(git_tree_owner(tree) == repo);
return git_commit__create_internal(
id, repo, update_ref, author, committer,
@@ -337,7 +340,8 @@
git_reference *ref;
int error;
- assert(id && commit_to_amend);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(commit_to_amend);
repo = git_commit_owner(commit_to_amend);
@@ -356,7 +360,7 @@
git_oid_cpy(&tree_id, git_tree_id(old_tree));
git_tree_free(old_tree);
} else {
- assert(git_tree_owner(tree) == repo);
+ GIT_ASSERT_ARG(git_tree_owner(tree) == repo);
git_oid_cpy(&tree_id, git_tree_id(tree));
}
@@ -392,7 +396,8 @@
size_t header_len;
git_signature dummy_sig;
- assert(commit && data);
+ GIT_ASSERT_ARG(commit);
+ GIT_ASSERT_ARG(data);
buffer = buffer_start;
@@ -506,28 +511,28 @@
return git_commit__parse_ext(_commit, odb_obj, 0);
}
-#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
+#define GIT_COMMIT_GETTER(_rvalue, _name, _return, _invalid) \
_rvalue git_commit_##_name(const git_commit *commit) \
{\
- assert(commit); \
+ GIT_ASSERT_ARG_WITH_RETVAL(commit, _invalid); \
return _return; \
}
-GIT_COMMIT_GETTER(const git_signature *, author, commit->author)
-GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer)
-GIT_COMMIT_GETTER(const char *, message_raw, commit->raw_message)
-GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding)
-GIT_COMMIT_GETTER(const char *, raw_header, commit->raw_header)
-GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
-GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
-GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)git_array_size(commit->parent_ids))
-GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id)
+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;
- assert(commit);
+ GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL);
message = commit->raw_message;
@@ -544,7 +549,7 @@
const char *msg, *space;
bool space_contains_newline = false;
- assert(commit);
+ GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL);
if (!commit->summary) {
for (msg = git_commit_message(commit), space = NULL; *msg; ++msg) {
@@ -587,7 +592,7 @@
{
const char *msg, *end;
- assert(commit);
+ GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL);
if (!commit->body) {
/* search for end of summary */
@@ -612,14 +617,14 @@
int git_commit_tree(git_tree **tree_out, const git_commit *commit)
{
- assert(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)
{
- assert(commit);
+ GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL);
return git_array_get(commit->parent_ids, n);
}
@@ -628,7 +633,7 @@
git_commit **parent, const git_commit *commit, unsigned int n)
{
const git_oid *parent_id;
- assert(commit);
+ GIT_ASSERT_ARG(commit);
parent_id = git_commit_parent_id(commit, n);
if (parent_id == NULL) {
@@ -647,7 +652,8 @@
git_commit *current, *parent = NULL;
int error;
- assert(ancestor && commit);
+ GIT_ASSERT_ARG(ancestor);
+ GIT_ASSERT_ARG(commit);
if (git_commit_dup(¤t, (git_commit *)commit) < 0)
return -1;
@@ -840,7 +846,8 @@
git_array_oid_t parents_arr = GIT_ARRAY_INIT;
const git_oid *tree_id;
- assert(tree && git_tree_owner(tree) == repo);
+ GIT_ASSERT_ARG(tree);
+ GIT_ASSERT_ARG(git_tree_owner(tree) == repo);
tree_id = git_tree_id(tree);
@@ -859,11 +866,13 @@
/**
* Append to 'out' properly marking continuations when there's a newline in 'content'
*/
-static void format_header_field(git_buf *out, const char *field, const char *content)
+static int format_header_field(git_buf *out, const char *field, const char *content)
{
const char *lf;
- assert(out && field && content);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(field);
+ GIT_ASSERT_ARG(content);
git_buf_puts(out, field);
git_buf_putc(out, ' ');
@@ -876,6 +885,8 @@
git_buf_puts(out, content);
git_buf_putc(out, '\n');
+
+ return git_buf_oom(out) ? -1 : 0;
}
static const git_oid *commit_parent_from_commit(size_t n, void *payload)
@@ -926,7 +937,9 @@
if (signature != NULL) {
field = signature_field ? signature_field : "gpgsig";
- format_header_field(&commit, field, signature);
+
+ if ((error = format_header_field(&commit, field, signature)) < 0)
+ goto cleanup;
}
git_buf_puts(&commit, header_end);
diff -Nru cargo-0.47.0/debian/libgit2/src/common.h cargo-0.51.0/debian/libgit2/src/common.h
--- cargo-0.47.0/debian/libgit2/src/common.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/common.h 2021-04-07 03:36:48.000000000 +0000
@@ -63,7 +63,9 @@
# include
# include
# endif
-#define GIT_STDLIB_CALL
+
+#define GIT_LIBGIT2_CALL
+#define GIT_SYSTEM_CALL
#ifdef GIT_USE_STAT_ATIMESPEC
# define st_atim st_atimespec
@@ -78,8 +80,9 @@
#include "git2/types.h"
#include "git2/errors.h"
#include "errors.h"
-#include "thread-utils.h"
+#include "thread.h"
#include "integer.h"
+#include "assert_safe.h"
/*
* Include the declarations for deprecated functions; this ensures
diff -Nru cargo-0.47.0/debian/libgit2/src/config.c cargo-0.51.0/debian/libgit2/src/config.c
--- cargo-0.47.0/debian/libgit2/src/config.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config.c 2021-04-07 03:36:48.000000000 +0000
@@ -108,7 +108,8 @@
struct stat st;
int res;
- assert(cfg && path);
+ GIT_ASSERT_ARG(cfg);
+ GIT_ASSERT_ARG(path);
res = p_stat(path, &st);
if (res < 0 && errno != ENOENT && errno != ENOTDIR) {
@@ -316,7 +317,8 @@
backend_internal *internal;
int result;
- assert(cfg && backend);
+ GIT_ASSERT_ARG(cfg);
+ GIT_ASSERT_ARG(backend);
GIT_ERROR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
@@ -514,7 +516,8 @@
git_regexp regex;
int error = 0;
- assert(backend && cb);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(cb);
if (regexp && git_regexp_compile(®ex, regexp, 0) < 0)
return -1;
@@ -886,7 +889,8 @@
int ret;
const char *str;
- git_buf_sanitize(out);
+ if ((ret = git_buf_sanitize(out)) < 0)
+ return ret;
ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
str = !ret ? (entry->value ? entry->value : "") : NULL;
@@ -1000,7 +1004,7 @@
return error;
}
-void multivar_iter_free(git_config_iterator *_iter)
+static void multivar_iter_free(git_config_iterator *_iter)
{
multivar_iter *iter = (multivar_iter *) _iter;
@@ -1084,19 +1088,31 @@
int git_config_find_global(git_buf *path)
{
- git_buf_sanitize(path);
+ int error;
+
+ if ((error = git_buf_sanitize(path)) < 0)
+ return error;
+
return git_sysdir_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL);
}
int git_config_find_xdg(git_buf *path)
{
- git_buf_sanitize(path);
+ int error;
+
+ if ((error = git_buf_sanitize(path)) < 0)
+ return error;
+
return git_sysdir_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG);
}
int git_config_find_system(git_buf *path)
{
- git_buf_sanitize(path);
+ int error;
+
+ if ((error = git_buf_sanitize(path)) < 0)
+ return error;
+
return git_sysdir_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
}
@@ -1104,7 +1120,9 @@
{
int ret;
- git_buf_sanitize(path);
+ if ((ret = git_buf_sanitize(path)) < 0)
+ return ret;
+
ret = git_sysdir_find_programdata_file(path,
GIT_CONFIG_FILENAME_PROGRAMDATA);
if (ret != GIT_OK)
@@ -1182,7 +1200,7 @@
git_config_backend *backend;
backend_internal *internal;
- assert(cfg);
+ GIT_ASSERT_ARG(cfg);
internal = git_vector_get(&cfg->backends, 0);
if (!internal || !internal->backend) {
@@ -1202,7 +1220,7 @@
git_config_backend *backend;
backend_internal *internal;
- assert(cfg);
+ GIT_ASSERT_ARG(cfg);
internal = git_vector_get(&cfg->backends, 0);
if (!internal || !internal->backend) {
@@ -1227,9 +1245,6 @@
{
size_t i;
- if (!value)
- goto fail_parse;
-
for (i = 0; i < map_n; ++i) {
const git_configmap *m = maps + i;
@@ -1238,7 +1253,7 @@
case GIT_CONFIGMAP_TRUE: {
int bool_val;
- if (git__parse_bool(&bool_val, value) == 0 &&
+ if (git_config_parse_bool(&bool_val, value) == 0 &&
bool_val == (int)m->type) {
*out = m->map_value;
return 0;
@@ -1252,7 +1267,7 @@
break;
case GIT_CONFIGMAP_STRING:
- if (strcasecmp(value, m->str_match) == 0) {
+ if (value && strcasecmp(value, m->str_match) == 0) {
*out = m->map_value;
return 0;
}
@@ -1260,7 +1275,6 @@
}
}
-fail_parse:
git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value);
return -1;
}
@@ -1364,9 +1378,13 @@
int git_config_parse_path(git_buf *out, const char *value)
{
- assert(out && value);
+ int error;
- git_buf_sanitize(out);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(value);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (value[0] == '~') {
if (value[1] != '\0' && value[1] != '/') {
@@ -1409,7 +1427,8 @@
{
char *name, *fdot, *ldot;
- assert(in && out);
+ GIT_ASSERT_ARG(in);
+ GIT_ASSERT_ARG(out);
name = git__strdup(in);
GIT_ERROR_CHECK_ALLOC(name);
diff -Nru cargo-0.47.0/debian/libgit2/src/config_cache.c cargo-0.51.0/debian/libgit2/src/config_cache.c
--- cargo-0.47.0/debian/libgit2/src/config_cache.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config_cache.c 2021-04-07 03:36:48.000000000 +0000
@@ -111,17 +111,21 @@
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
{
- *out = repo->configmap_cache[(int)item];
+ intptr_t value = (intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
- if (*out == GIT_CONFIGMAP_NOT_CACHED) {
- int error;
+ *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;
- repo->configmap_cache[(int)item] = *out;
+ value = *out;
+ git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], (void *)oldval, (void *)value);
}
return 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/config_entries.c cargo-0.51.0/debian/libgit2/src/config_entries.c
--- cargo-0.47.0/debian/libgit2/src/config_entries.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config_entries.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,9 +11,13 @@
struct config_entry_list *next;
struct config_entry_list *last;
git_config_entry *entry;
- bool first;
} config_entry_list;
+typedef struct {
+ git_config_entry *entry;
+ bool multivar;
+} config_entry_map_head;
+
typedef struct config_entries_iterator {
git_config_iterator parent;
git_config_entries *entries;
@@ -102,14 +106,16 @@
static void config_entries_free(git_config_entries *entries)
{
config_entry_list *list = NULL, *next;
+ config_entry_map_head *head;
+ git_strmap_foreach_value(entries->map, head,
+ git__free((char *) head->entry->name); git__free(head)
+ );
git_strmap_free(entries->map);
list = entries->list;
while (list != NULL) {
next = list->next;
- if (list->first)
- git__free((char *) list->entry->name);
git__free((char *) list->entry->value);
git__free(list->entry);
git__free(list);
@@ -127,40 +133,42 @@
int git_config_entries_append(git_config_entries *entries, git_config_entry *entry)
{
- config_entry_list *existing, *head;
+ config_entry_list *list_head;
+ config_entry_map_head *map_head;
- head = git__calloc(1, sizeof(config_entry_list));
- GIT_ERROR_CHECK_ALLOC(head);
- head->entry = entry;
-
- /*
- * 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 entries, we can just free
- * all except the first entry's name and just re-use it.
- */
- if ((existing = git_strmap_get(entries->map, entry->name)) != NULL) {
+ if ((map_head = git_strmap_get(entries->map, entry->name)) != NULL) {
+ 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 entries, we can just free
+ * all except the first entry's name and just re-use it.
+ */
git__free((char *) entry->name);
- entry->name = existing->entry->name;
+ entry->name = map_head->entry->name;
} else {
- head->first = 1;
+ map_head = git__calloc(1, sizeof(*map_head));
+ if ((git_strmap_set(entries->map, 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 (entries->list)
- entries->list->last->next = head;
+ entries->list->last->next = list_head;
else
- entries->list = head;
- entries->list->last = head;
-
- if (git_strmap_set(entries->map, entry->name, head) < 0)
- return -1;
+ entries->list = list_head;
+ entries->list->last = list_head;
return 0;
}
int git_config_entries_get(git_config_entry **out, git_config_entries *entries, const char *key)
{
- config_entry_list *entry;
+ config_entry_map_head *entry;
if ((entry = git_strmap_get(entries->map, key)) == NULL)
return GIT_ENOTFOUND;
*out = entry->entry;
@@ -169,12 +177,12 @@
int git_config_entries_get_unique(git_config_entry **out, git_config_entries *entries, const char *key)
{
- config_entry_list *entry;
+ config_entry_map_head *entry;
if ((entry = git_strmap_get(entries->map, key)) == NULL)
return GIT_ENOTFOUND;
- if (!entry->first) {
+ if (entry->multivar) {
git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being a multivar");
return -1;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/config_file.c cargo-0.51.0/debian/libgit2/src/config_file.c
--- cargo-0.47.0/debian/libgit2/src/config_file.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config_file.c 2021-04-07 03:36:48.000000000 +0000
@@ -111,6 +111,15 @@
if (!git_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->entries, repo, &b->file, level, 0)) < 0) {
git_config_entries_free(b->entries);
b->entries = NULL;
@@ -356,7 +365,7 @@
int result;
char *key;
- assert(regexp);
+ GIT_ASSERT_ARG(regexp);
if ((result = git_config__normalize_name(name, &key)) < 0)
return result;
@@ -522,7 +531,7 @@
size_t len;
const char *esc;
- assert(ptr);
+ GIT_ASSERT_ARG_WITH_RETVAL(ptr, NULL);
len = strlen(ptr);
if (!len)
diff -Nru cargo-0.47.0/debian/libgit2/src/config_parse.c cargo-0.51.0/debian/libgit2/src/config_parse.c
--- cargo-0.47.0/debian/libgit2/src/config_parse.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config_parse.c 2021-04-07 03:36:48.000000000 +0000
@@ -187,7 +187,7 @@
/* Make sure we were given a section header */
c = line[pos++];
- assert(c == '[');
+ GIT_ASSERT(c == '[');
c = line[pos++];
@@ -451,7 +451,7 @@
git_buf_attach(&multi_value, value, 0);
value = NULL;
- if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 ||
+ if (parse_multiline_variable(reader, &multi_value, quote_count % 2) < 0 ||
git_buf_oom(&multi_value)) {
error = -1;
git_buf_dispose(&multi_value);
diff -Nru cargo-0.47.0/debian/libgit2/src/config_snapshot.c cargo-0.51.0/debian/libgit2/src/config_snapshot.c
--- cargo-0.47.0/debian/libgit2/src/config_snapshot.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/config_snapshot.c 2021-04-07 03:36:48.000000000 +0000
@@ -5,8 +5,9 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "config.h"
+#include "config_backend.h"
+#include "config.h"
#include "config_entries.h"
typedef struct {
diff -Nru cargo-0.47.0/debian/libgit2/src/date.c cargo-0.51.0/debian/libgit2/src/date.c
--- cargo-0.47.0/debian/libgit2/src/date.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/date.c 2021-04-07 03:36:48.000000000 +0000
@@ -881,7 +881,8 @@
struct tm gmt;
time_t t;
- assert(out && date);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(date);
t = (time_t) (date->time + date->offset * 60);
diff -Nru cargo-0.47.0/debian/libgit2/src/delta.c cargo-0.51.0/debian/libgit2/src/delta.c
--- cargo-0.47.0/debian/libgit2/src/delta.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/delta.c 2021-04-07 03:36:48.000000000 +0000
@@ -256,7 +256,7 @@
size_t git_delta_index_size(git_delta_index *index)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
return index->memsize;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/describe.c cargo-0.51.0/debian/libgit2/src/describe.c
--- cargo-0.47.0/debian/libgit2/src/describe.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/describe.c 2021-04-07 03:36:48.000000000 +0000
@@ -655,7 +655,8 @@
int error = -1;
git_describe_options normalized;
- assert(committish);
+ GIT_ASSERT_ARG(result);
+ GIT_ASSERT_ARG(committish);
data.result = git__calloc(1, sizeof(git_describe_result));
GIT_ERROR_CHECK_ALLOC(data.result);
@@ -685,7 +686,7 @@
get_name, &data)) < 0)
goto cleanup;
- if (git_oidmap_size(data.names) == 0 && !opts->show_commit_oid_as_fallback) {
+ if (git_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;
@@ -775,12 +776,14 @@
struct commit_name *name;
git_describe_format_options opts;
- assert(out && result);
+ 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);
- git_buf_sanitize(out);
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (opts.always_use_long_format && opts.abbreviated_size == 0) {
@@ -876,10 +879,12 @@
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)
{
@@ -888,7 +893,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/diff.c cargo-0.51.0/debian/libgit2/src/diff.c
--- cargo-0.47.0/debian/libgit2/src/diff.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff.c 2021-04-07 03:36:48.000000000 +0000
@@ -32,11 +32,6 @@
return str;
}
-const char *git_diff_delta__path(const git_diff_delta *delta)
-{
- return diff_delta__path(delta);
-}
-
int git_diff_delta__cmp(const void *a, const void *b)
{
const git_diff_delta *da = a, *db = b;
@@ -82,7 +77,7 @@
size_t git_diff_num_deltas(const git_diff *diff)
{
- assert(diff);
+ GIT_ASSERT_ARG(diff);
return diff->deltas.length;
}
@@ -91,7 +86,7 @@
size_t i, count = 0;
const git_diff_delta *delta;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
git_vector_foreach(&diff->deltas, i, delta) {
count += (delta->status == type);
@@ -102,7 +97,7 @@
const git_diff_delta *git_diff_get_delta(const git_diff *diff, size_t idx)
{
- assert(diff);
+ GIT_ASSERT_ARG_WITH_RETVAL(diff, NULL);
return git_vector_get(&diff->deltas, idx);
}
@@ -113,7 +108,7 @@
int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
{
- assert(out);
+ 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;
@@ -132,7 +127,7 @@
git_diff_delta *delta;
size_t idx;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
git_vector_foreach(&diff->deltas, idx, delta) {
git_patch *patch;
@@ -155,7 +150,7 @@
return error;
}
-int git_diff_format_email__append_header_tobuf(
+static int diff_format_email_append_header_tobuf(
git_buf *out,
const git_oid *id,
const git_signature *author,
@@ -212,7 +207,7 @@
return error;
}
-int git_diff_format_email__append_patches_tobuf(
+static int diff_format_email_append_patches_tobuf(
git_buf *out,
git_diff *diff)
{
@@ -248,8 +243,9 @@
size_t allocsize;
int error;
- assert(out && diff && opts);
- assert(opts->summary && opts->id && opts->author);
+ 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,
@@ -292,7 +288,7 @@
strncpy(summary, opts->summary, offset);
}
- error = git_diff_format_email__append_header_tobuf(out,
+ error = diff_format_email_append_header_tobuf(out,
opts->id, opts->author, summary == NULL ? opts->summary : summary,
opts->body, opts->patch_no, opts->total_patches, ignore_marker);
@@ -305,7 +301,7 @@
(error = git_diff_get_stats(&stats, diff)) < 0 ||
(error = git_diff_stats_to_buf(out, stats, format_flags, 0)) < 0 ||
(error = git_buf_putc(out, '\n')) < 0 ||
- (error = git_diff_format_email__append_patches_tobuf(out, diff)) < 0)
+ (error = diff_format_email_append_patches_tobuf(out, diff)) < 0)
goto on_error;
error = git_buf_puts(out, "--\nlibgit2 " LIBGIT2_VERSION "\n\n");
@@ -331,7 +327,9 @@
GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
int error;
- assert (out && repo && commit);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commit);
opts.flags = flags;
opts.patch_no = patch_no;
@@ -357,10 +355,12 @@
return 0;
}
+#ifndef GIT_DEPRECATE_HARD
int git_diff_init_options(git_diff_options *opts, unsigned int version)
{
return git_diff_options_init(opts, version);
}
+#endif
int git_diff_find_options_init(
git_diff_find_options *opts, unsigned int version)
@@ -370,11 +370,13 @@
return 0;
}
+#ifndef GIT_DEPRECATE_HARD
int git_diff_find_init_options(
git_diff_find_options *opts, unsigned int version)
{
return git_diff_find_options_init(opts, version);
}
+#endif
int git_diff_format_email_options_init(
git_diff_format_email_options *opts, unsigned int version)
@@ -385,11 +387,13 @@
return 0;
}
+#ifndef GIT_DEPRECATE_HARD
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
static int flush_hunk(git_oid *result, git_hash_ctx *ctx)
{
@@ -426,7 +430,7 @@
git_buf_truncate(buf, len);
}
-int git_diff_patchid_print_callback__to_buf(
+static int diff_patchid_print_callback_to_buf(
const git_diff_delta *delta,
const git_diff_hunk *hunk,
const git_diff_line *line,
@@ -485,7 +489,7 @@
if ((error = git_diff_print(diff,
GIT_DIFF_FORMAT_PATCH_ID,
- git_diff_patchid_print_callback__to_buf,
+ diff_patchid_print_callback_to_buf,
&args)) < 0)
goto out;
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_driver.c cargo-0.51.0/debian/libgit2/src/diff_driver.c
--- cargo-0.47.0/debian/libgit2/src/diff_driver.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_driver.c 2021-04-07 03:36:48.000000000 +0000
@@ -144,7 +144,7 @@
{
if (!repo->diff_drivers) {
git_diff_driver_registry *reg = git_diff_driver_registry_new();
- reg = git__compare_and_swap(&repo->diff_drivers, NULL, reg);
+ reg = git_atomic_compare_and_swap(&repo->diff_drivers, NULL, reg);
if (reg != NULL) /* if we race, free losing allocation */
git_diff_driver_registry_free(reg);
@@ -358,7 +358,7 @@
int error = 0;
const char *values[1], *attrs[] = { "diff" };
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
if (!repo || !path || !strlen(path))
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_file.c cargo-0.51.0/debian/libgit2/src/diff_file.c
--- cargo-0.47.0/debian/libgit2/src/diff_file.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_file.c 2021-04-07 03:36:48.000000000 +0000
@@ -160,8 +160,10 @@
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)) < 0)
+ return error;
fc->file->size = src->buflen;
- git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB);
fc->file->id_abbrev = GIT_OID_HEXSZ;
fc->map.len = src->buflen;
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_generate.c cargo-0.51.0/debian/libgit2/src/diff_generate.c
--- cargo-0.47.0/debian/libgit2/src/diff_generate.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_generate.c 2021-04-07 03:36:48.000000000 +0000
@@ -128,7 +128,7 @@
git_diff_delta *delta;
const char *matched_pathspec;
- assert((oitem != NULL) ^ (nitem != NULL));
+ GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL));
if (oitem) {
entry = oitem;
@@ -160,7 +160,7 @@
GIT_ERROR_CHECK_ALLOC(delta);
/* This fn is just for single-sided diffs */
- assert(status != GIT_DELTA_MODIFIED);
+ GIT_ASSERT(status != GIT_DELTA_MODIFIED);
delta->nfiles = 1;
if (has_old) {
@@ -301,14 +301,14 @@
delta->old_file.path : delta->new_file.path;
}
-int git_diff_delta__i2w_cmp(const void *a, const void *b)
+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);
}
-int git_diff_delta__i2w_casecmp(const void *a, const void *b)
+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));
@@ -361,7 +361,7 @@
return pfx;
}
-void git_diff__set_ignore_case(git_diff *diff, bool ignore_case)
+static void diff_set_ignore_case(git_diff *diff, bool ignore_case)
{
if (!ignore_case) {
diff->opts.flags &= ~GIT_DIFF_IGNORE_CASE;
@@ -408,7 +408,9 @@
git_diff_generated *diff;
git_diff_options dflt = GIT_DIFF_OPTIONS_INIT;
- assert(repo && old_iter && new_iter);
+ 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;
@@ -423,16 +425,15 @@
git_attr_session__init(&diff->base.attrsession, repo);
memcpy(&diff->base.opts, &dflt, sizeof(git_diff_options));
- git_pool_init(&diff->base.pool, 1);
-
- if (git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
+ 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 */
- git_diff__set_ignore_case(
+ diff_set_ignore_case(
&diff->base,
git_iterator_ignore_case(old_iter) ||
git_iterator_ignore_case(new_iter));
@@ -590,7 +591,7 @@
git_filter_list *fl = NULL;
int error = 0;
- assert(d->type == GIT_DIFF_TYPE_GENERATED);
+ GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED);
diff = (git_diff_generated *)d;
memset(out, 0, sizeof(*out));
@@ -679,6 +680,8 @@
git_iterator *new_iter;
const git_index_entry *oitem;
const git_index_entry *nitem;
+ git_strmap *submodule_cache;
+ bool submodule_cache_initialized;
} diff_in_progress;
#define MODE_BITS_MASK 0000777
@@ -693,6 +696,7 @@
git_submodule *sub;
unsigned int sm_status = 0;
git_submodule_ignore_t ign = diff->base.opts.ignore_submodules;
+ git_strmap *submodule_cache = NULL;
*status = GIT_DELTA_UNMODIFIED;
@@ -700,8 +704,23 @@
ign == GIT_SUBMODULE_IGNORE_ALL)
return 0;
- if ((error = git_submodule_lookup(
- &sub, diff->base.repo, info->nitem->path)) < 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) {
@@ -1191,7 +1210,7 @@
const git_diff_options *opts)
{
git_diff_generated *diff;
- diff_in_progress info;
+ diff_in_progress info = {0};
int error = 0;
*out = NULL;
@@ -1205,8 +1224,9 @@
/* make iterators have matching icase behavior */
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) {
- git_iterator_set_ignore_case(old_iter, true);
- git_iterator_set_ignore_case(new_iter, true);
+ 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 */
@@ -1258,6 +1278,8 @@
*out = &diff->base;
else
git_diff_free(&diff->base);
+ if (info.submodule_cache)
+ git_submodule_cache_free(info.submodule_cache);
return error;
}
@@ -1303,7 +1325,8 @@
char *prefix = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1359,7 +1382,8 @@
bool index_ignore_case = false;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1376,7 +1400,7 @@
/* if index is in case-insensitive order, re-sort deltas to match */
if (index_ignore_case)
- git_diff__set_ignore_case(diff, true);
+ diff_set_ignore_case(diff, true);
*out = diff;
diff = NULL;
@@ -1402,7 +1426,8 @@
char *prefix = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1445,7 +1470,8 @@
git_index *index;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1478,7 +1504,8 @@
git_index *index = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1514,7 +1541,9 @@
char *prefix = NULL;
int error;
- assert(out && old_index && new_index);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(old_index);
+ GIT_ASSERT_ARG(new_index);
*out = NULL;
@@ -1527,7 +1556,7 @@
/* if index is in case-insensitive order, re-sort deltas to match */
if (old_index->ignore_case || new_index->ignore_case)
- git_diff__set_ignore_case(diff, true);
+ diff_set_ignore_case(diff, true);
*out = diff;
diff = NULL;
@@ -1584,10 +1613,10 @@
if (i2w_icase && !icase_mismatch) {
strcomp = git__strcasecmp;
- git_vector_set_cmp(&idx2wd->deltas, git_diff_delta__i2w_casecmp);
+ 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, git_diff_delta__i2w_cmp);
+ git_vector_set_cmp(&idx2wd->deltas, diff_delta_i2w_cmp);
git_vector_sort(&idx2wd->deltas);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_parse.c cargo-0.51.0/debian/libgit2/src/diff_parse.c
--- cargo-0.47.0/debian/libgit2/src/diff_parse.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_parse.c 2021-04-07 03:36:48.000000000 +0000
@@ -52,9 +52,8 @@
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
- git_pool_init(&diff->base.pool, 1);
-
- if (git_vector_init(&diff->patches, 0, NULL) < 0 ||
+ 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;
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_print.c cargo-0.51.0/debian/libgit2/src/diff_print.c
--- cargo-0.47.0/debian/libgit2/src/diff_print.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_print.c 2021-04-07 03:36:48.000000000 +0000
@@ -95,7 +95,7 @@
git_diff_line_cb cb,
void *payload)
{
- assert(patch);
+ GIT_ASSERT_ARG(patch);
memset(pi, 0, sizeof(diff_print_info));
@@ -337,7 +337,7 @@
return git_buf_printf(out, template, oldpath, newpath);
}
-int diff_delta_format_similarity_header(
+static int diff_delta_format_similarity_header(
git_buf *out,
const git_diff_delta *delta)
{
@@ -351,17 +351,16 @@
goto done;
}
+ GIT_ASSERT(delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED);
if (delta->status == GIT_DELTA_RENAMED)
type = "rename";
- else if (delta->status == GIT_DELTA_COPIED)
- type = "copy";
else
- abort();
+ type = "copy";
if ((error = git_buf_puts(&old_path, delta->old_file.path)) < 0 ||
- (error = git_buf_puts(&new_path, delta->new_file.path)) < 0 ||
- (error = git_buf_quote(&old_path)) < 0 ||
- (error = git_buf_quote(&new_path)) < 0)
+ (error = git_buf_puts(&new_path, delta->new_file.path)) < 0 ||
+ (error = git_buf_quote(&old_path)) < 0 ||
+ (error = git_buf_quote(&new_path)) < 0)
goto done;
git_buf_printf(out,
@@ -428,8 +427,11 @@
git_buf_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)) {
+ (delta->status == GIT_DELTA_COPIED && unchanged)) {
if ((error = diff_delta_format_similarity_header(out, delta)) < 0)
goto done;
}
@@ -444,9 +446,6 @@
"--- %s\n+++ %s\n", old_path.ptr, new_path.ptr);
}
- if (unchanged && delta->old_file.mode != delta->new_file.mode)
- diff_print_modes(out, delta);
-
if (git_buf_oom(out))
error = -1;
@@ -492,6 +491,9 @@
}
git_buf_putc(pi->buf, '\n');
+ if (git_buf_oom(pi->buf))
+ return -1;
+
return 0;
}
@@ -502,21 +504,17 @@
git_buf old_path = GIT_BUF_INIT, new_path = GIT_BUF_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)
+ 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;
- error = diff_delta_format_with_paths(
- pi->buf, delta, "Binary files %s and %s differ\n",
- old_path.ptr, new_path.ptr);
done:
git_buf_dispose(&old_path);
git_buf_dispose(&new_path);
-
return error;
}
@@ -540,10 +538,9 @@
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) {
-
+ 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_buf_truncate(pi->buf, pre_binary_size);
@@ -580,16 +577,15 @@
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 &&
+ 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;
- if ((error = git_diff_delta__format_file_header(
- pi->buf, delta, oldpfx, newpfx,
- id_strlen, print_index)) < 0)
+ if ((error = git_diff_delta__format_file_header(pi->buf, delta, oldpfx, newpfx,
+ id_strlen, print_index)) < 0)
return error;
pi->line.origin = GIT_DIFF_LINE_FILE_HDR;
@@ -699,17 +695,16 @@
return -1;
}
- if (!(error = diff_print_info_init_fromdiff(
- &pi, &buf, diff, format, print_cb, payload))) {
- error = git_diff_foreach(
- diff, print_file, print_binary, print_hunk, print_line, &pi);
+ if ((error = diff_print_info_init_fromdiff(&pi, &buf, diff, format, print_cb, payload)) < 0)
+ goto out;
- if (error) /* make sure error message is set */
- git_error_set_after_callback_function(error, "git_diff_print");
+ 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_buf_dispose(&buf);
-
return error;
}
@@ -728,8 +723,8 @@
}
if (line->origin == GIT_DIFF_LINE_ADDITION ||
- line->origin == GIT_DIFF_LINE_DELETION ||
- line->origin == GIT_DIFF_LINE_CONTEXT)
+ line->origin == GIT_DIFF_LINE_DELETION ||
+ line->origin == GIT_DIFF_LINE_CONTEXT)
git_buf_putc(output, line->origin);
return git_buf_put(output, line->content, line->content_len);
@@ -742,24 +737,42 @@
void *payload)
{
FILE *fp = payload ? payload : stdout;
+ int error;
- GIT_UNUSED(delta); GIT_UNUSED(hunk);
+ 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)
- fputc(line->origin, fp);
- fwrite(line->content, 1, line->content_len, fp);
+ 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_buf */
int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
{
- assert(out && diff);
- git_buf_sanitize(out);
- return git_diff_print(
- diff, format, git_diff_print_callback__to_buf, out);
+ int error;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
+
+ return git_diff_print(diff, format, git_diff_print_callback__to_buf, out);
}
/* print a git_patch to an output callback */
@@ -768,35 +781,38 @@
git_diff_line_cb print_cb,
void *payload)
{
- int error;
git_buf temp = GIT_BUF_INIT;
diff_print_info pi;
+ int error;
- assert(patch && print_cb);
+ 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)))
- {
- error = git_patch__invoke_callbacks(
- patch,
- diff_print_patch_file, diff_print_patch_binary,
- diff_print_patch_hunk, diff_print_patch_line,
- &pi);
+ if ((error = diff_print_info_init_frompatch(&pi, &temp, patch,
+ GIT_DIFF_FORMAT_PATCH, print_cb, payload)) < 0)
+ goto out;
- if (error) /* make sure error message is set */
- git_error_set_after_callback_function(error, "git_patch_print");
+ 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_buf_dispose(&temp);
-
return error;
}
/* print a git_patch to a git_buf */
int git_patch_to_buf(git_buf *out, git_patch *patch)
{
- assert(out && patch);
- git_buf_sanitize(out);
+ int error;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(patch);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
+
return git_patch_print(patch, git_diff_print_callback__to_buf, out);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_stats.c cargo-0.51.0/debian/libgit2/src/diff_stats.c
--- cargo-0.47.0/debian/libgit2/src/diff_stats.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_stats.c 2021-04-07 03:36:48.000000000 +0000
@@ -46,14 +46,14 @@
return count;
}
-int git_diff_file_stats__full_to_buf(
+static int diff_file_stats_full_to_buf(
git_buf *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;
+ const char *old_path = NULL, *new_path = NULL, *adddel_path = NULL;
size_t padding;
git_object_size_t old_size, new_size;
@@ -62,7 +62,7 @@
old_size = delta->old_file.size;
new_size = delta->new_file.size;
- if (strcmp(old_path, new_path) != 0) {
+ if (old_path && new_path && strcmp(old_path, new_path) != 0) {
size_t common_dirlen;
int error;
@@ -82,10 +82,11 @@
if (error < 0)
goto on_error;
} else {
- if (git_buf_printf(out, " %s", old_path) < 0)
+ adddel_path = new_path ? new_path : old_path;
+ if (git_buf_printf(out, " %s", adddel_path) < 0)
goto on_error;
- padding = stats->max_name - strlen(old_path);
+ padding = stats->max_name - strlen(adddel_path);
if (stats->renames > 0)
padding += strlen(DIFF_RENAME_FILE_SEPARATOR);
@@ -134,7 +135,7 @@
return (git_buf_oom(out) ? -1 : 0);
}
-int git_diff_file_stats__number_to_buf(
+static int diff_file_stats_number_to_buf(
git_buf *out,
const git_diff_delta *delta,
const diff_file_stats *filestats)
@@ -151,7 +152,7 @@
return error;
}
-int git_diff_file_stats__summary_to_buf(
+static int diff_file_stats_summary_to_buf(
git_buf *out,
const git_diff_delta *delta)
{
@@ -182,7 +183,8 @@
git_diff_stats *stats = NULL;
int error = 0;
- assert(out && diff);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
stats = git__calloc(1, sizeof(git_diff_stats));
GIT_ERROR_CHECK_ALLOC(stats);
@@ -211,7 +213,7 @@
/* TODO ugh */
namelen = strlen(delta->new_file.path);
- if (strcmp(delta->old_file.path, delta->new_file.path) != 0) {
+ if (delta->old_file.path && strcmp(delta->old_file.path, delta->new_file.path) != 0) {
namelen += strlen(delta->old_file.path);
stats->renames++;
}
@@ -250,7 +252,7 @@
size_t git_diff_stats_files_changed(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->files_changed;
}
@@ -258,7 +260,7 @@
size_t git_diff_stats_insertions(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->insertions;
}
@@ -266,7 +268,7 @@
size_t git_diff_stats_deletions(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->deletions;
}
@@ -281,14 +283,15 @@
size_t i;
const git_diff_delta *delta;
- assert(out && stats);
+ 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 = git_diff_file_stats__number_to_buf(
+ error = diff_file_stats_number_to_buf(
out, delta, &stats->filestats[i]);
if (error < 0)
return error;
@@ -309,7 +312,7 @@
if ((delta = git_diff_get_delta(stats->diff, i)) == NULL)
continue;
- error = git_diff_file_stats__full_to_buf(
+ error = diff_file_stats_full_to_buf(
out, delta, &stats->filestats[i], stats, width);
if (error < 0)
return error;
@@ -342,7 +345,7 @@
if ((delta = git_diff_get_delta(stats->diff, i)) == NULL)
continue;
- error = git_diff_file_stats__summary_to_buf(out, delta);
+ error = diff_file_stats_summary_to_buf(out, delta);
if (error < 0)
return error;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/diff_tform.c cargo-0.51.0/debian/libgit2/src/diff_tform.c
--- cargo-0.47.0/debian/libgit2/src/diff_tform.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/diff_tform.c 2021-04-07 03:36:48.000000000 +0000
@@ -87,7 +87,7 @@
a->status == GIT_DELTA_UNREADABLE)
return dup;
- assert(b->status != GIT_DELTA_UNMODIFIED);
+ 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.
@@ -121,7 +121,8 @@
bool ignore_case, reversed;
unsigned int i, j;
- assert(onto && from);
+ GIT_ASSERT_ARG(onto);
+ GIT_ASSERT_ARG(from);
if (!from->deltas.length)
return 0;
@@ -136,11 +137,10 @@
return -1;
}
- if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
+ if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
+ git_pool_init(&onto_pool, 1) < 0)
return -1;
- git_pool_init(&onto_pool, 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);
@@ -816,7 +816,7 @@
diff_find_match *best_match;
git_diff_file swap;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
return error;
@@ -979,7 +979,7 @@
src->flags |= GIT_DIFF_FLAG__TO_DELETE;
num_rewrites++;
} else {
- assert(delta_is_split(tgt));
+ GIT_ASSERT(delta_is_split(tgt));
if (best_match->similarity < opts.rename_from_rewrite_threshold)
continue;
@@ -989,7 +989,7 @@
delta_make_rename(tgt, src, best_match->similarity);
num_rewrites--;
- assert(src->status == GIT_DELTA_DELETED);
+ 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;
@@ -1025,7 +1025,7 @@
num_updates++;
} else {
- assert(delta_is_split(src));
+ GIT_ASSERT(delta_is_split(src));
if (best_match->similarity < opts.rename_from_rewrite_threshold)
continue;
diff -Nru cargo-0.47.0/debian/libgit2/src/errors.c cargo-0.51.0/debian/libgit2/src/errors.c
--- cargo-0.47.0/debian/libgit2/src/errors.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/errors.c 2021-04-07 03:36:48.000000000 +0000
@@ -7,9 +7,10 @@
#include "common.h"
-#include "global.h"
+#include "threadstate.h"
#include "posix.h"
#include "buffer.h"
+#include "libgit2.h"
/********************************************
* New error handling
@@ -20,20 +21,25 @@
GIT_ERROR_NOMEMORY
};
+static git_error g_git_uninitialized_error = {
+ "libgit2 has not been initialized; you must call git_libgit2_init",
+ GIT_ERROR_INVALID
+};
+
static void set_error_from_buffer(int error_class)
{
- git_error *error = &GIT_GLOBAL->error_t;
- git_buf *buf = &GIT_GLOBAL->error_buf;
+ git_error *error = &GIT_THREADSTATE->error_t;
+ git_buf *buf = &GIT_THREADSTATE->error_buf;
error->message = buf->ptr;
error->klass = error_class;
- GIT_GLOBAL->last_error = error;
+ GIT_THREADSTATE->last_error = error;
}
static void set_error(int error_class, char *string)
{
- git_buf *buf = &GIT_GLOBAL->error_buf;
+ git_buf *buf = &GIT_THREADSTATE->error_buf;
git_buf_clear(buf);
if (string) {
@@ -46,7 +52,7 @@
void git_error_set_oom(void)
{
- GIT_GLOBAL->last_error = &g_git_oom_error;
+ GIT_THREADSTATE->last_error = &g_git_oom_error;
}
void git_error_set(int error_class, const char *fmt, ...)
@@ -64,7 +70,7 @@
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
#endif
int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
- git_buf *buf = &GIT_GLOBAL->error_buf;
+ git_buf *buf = &GIT_THREADSTATE->error_buf;
git_buf_clear(buf);
if (fmt) {
@@ -97,9 +103,9 @@
int git_error_set_str(int error_class, const char *string)
{
- git_buf *buf = &GIT_GLOBAL->error_buf;
+ git_buf *buf = &GIT_THREADSTATE->error_buf;
- assert(string);
+ GIT_ASSERT_ARG(string);
if (!string) {
git_error_set(GIT_ERROR_INVALID, "unspecified caller error");
@@ -118,9 +124,9 @@
void git_error_clear(void)
{
- if (GIT_GLOBAL->last_error != NULL) {
+ if (GIT_THREADSTATE->last_error != NULL) {
set_error(0, NULL);
- GIT_GLOBAL->last_error = NULL;
+ GIT_THREADSTATE->last_error = NULL;
}
errno = 0;
@@ -131,13 +137,17 @@
const git_error *git_error_last(void)
{
- return GIT_GLOBAL->last_error;
+ /* If the library is not initialized, return a static error. */
+ if (!git_libgit2_init_count())
+ return &g_git_uninitialized_error;
+
+ return GIT_THREADSTATE->last_error;
}
int git_error_state_capture(git_error_state *state, int error_code)
{
- git_error *error = GIT_GLOBAL->last_error;
- git_buf *error_buf = &GIT_GLOBAL->error_buf;
+ git_error *error = GIT_THREADSTATE->last_error;
+ git_buf *error_buf = &GIT_THREADSTATE->error_buf;
memset(state, 0, sizeof(git_error_state));
@@ -210,6 +220,7 @@
/* Deprecated error values and functions */
+#ifndef GIT_DEPRECATE_HARD
const git_error *giterr_last(void)
{
return git_error_last();
@@ -229,3 +240,4 @@
{
git_error_set_oom();
}
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/features.h.in cargo-0.51.0/debian/libgit2/src/features.h.in
--- cargo-0.47.0/debian/libgit2/src/features.h.in 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/features.h.in 2021-04-07 03:36:48.000000000 +0000
@@ -4,7 +4,7 @@
#cmakedefine GIT_DEBUG_POOL 1
#cmakedefine GIT_TRACE 1
#cmakedefine GIT_THREADS 1
-#cmakedefine GIT_MSVC_CRTDBG 1
+#cmakedefine GIT_WIN32_LEAKCHECK 1
#cmakedefine GIT_ARCH_64 1
#cmakedefine GIT_ARCH_32 1
diff -Nru cargo-0.47.0/debian/libgit2/src/fetch.c cargo-0.51.0/debian/libgit2/src/fetch.c
--- cargo-0.47.0/debian/libgit2/src/fetch.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/fetch.c 2021-04-07 03:36:48.000000000 +0000
@@ -21,9 +21,12 @@
static int maybe_want(git_remote *remote, git_remote_head *head, git_odb *odb, git_refspec *tagspec, git_remote_autotag_option_t tagopt)
{
- int match = 0;
+ int match = 0, valid;
- if (!git_reference_is_valid_name(head->name))
+ if (git_reference_name_is_valid(&valid, head->name) < 0)
+ return -1;
+
+ if (!valid)
return 0;
if (tagopt == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
@@ -155,7 +158,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/fetchhead.c cargo-0.51.0/debian/libgit2/src/fetchhead.c
--- cargo-0.47.0/debian/libgit2/src/fetchhead.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/fetchhead.c 2021-04-07 03:36:48.000000000 +0000
@@ -73,7 +73,8 @@
{
git_fetchhead_ref *fetchhead_ref;
- assert(out && oid);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(oid);
*out = NULL;
@@ -108,7 +109,8 @@
const char *type, *name;
int head = 0;
- assert(file && fetchhead_ref);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(fetchhead_ref);
git_oid_fmt(oid, &fetchhead_ref->oid);
oid[GIT_OID_HEXSZ] = '\0';
@@ -145,7 +147,8 @@
unsigned int i;
git_fetchhead_ref *fetchhead_ref;
- assert(repo && fetchhead_refs);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(fetchhead_refs);
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
@@ -279,7 +282,8 @@
size_t line_num = 0;
int error = 0;
- assert(repo && cb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(cb);
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
diff -Nru cargo-0.47.0/debian/libgit2/src/filebuf.c cargo-0.51.0/debian/libgit2/src/filebuf.c
--- cargo-0.47.0/debian/libgit2/src/filebuf.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/filebuf.c 2021-04-07 03:36:48.000000000 +0000
@@ -184,7 +184,7 @@
} while (zs->avail_out == 0);
- assert(zs->avail_in == 0);
+ GIT_ASSERT(zs->avail_in == 0);
if (file->compute_digest)
git_hash_update(&file->digest, source, len);
@@ -278,10 +278,9 @@
int compression, error = -1;
size_t path_len, alloc_len;
- /* opening an already open buffer is a programming error;
- * assert that this never happens instead of returning
- * an error code */
- assert(file && path && file->buffer == NULL);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(path);
+ GIT_ASSERT(file->buffer == NULL);
memset(file, 0x0, sizeof(git_filebuf));
@@ -389,7 +388,9 @@
int git_filebuf_hash(git_oid *oid, git_filebuf *file)
{
- assert(oid && file && file->compute_digest);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(file->compute_digest);
flush_buffer(file);
@@ -415,7 +416,8 @@
int git_filebuf_commit(git_filebuf *file)
{
/* temporary files cannot be committed */
- assert(file && file->path_original);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT(file->path_original);
file->flush_mode = Z_FINISH;
flush_buffer(file);
diff -Nru cargo-0.47.0/debian/libgit2/src/filter.c cargo-0.51.0/debian/libgit2/src/filter.c
--- cargo-0.47.0/debian/libgit2/src/filter.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/filter.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,7 +11,7 @@
#include "futils.h"
#include "hash.h"
#include "repository.h"
-#include "global.h"
+#include "runtime.h"
#include "git2/sys/filter.h"
#include "git2/config.h"
#include "blob.h"
@@ -206,7 +206,7 @@
GIT_FILTER_IDENT, ident, GIT_FILTER_IDENT_PRIORITY) < 0)
error = -1;
- git__on_shutdown(git_filter_global_shutdown);
+ error = git_runtime_shutdown_register(git_filter_global_shutdown);
done:
if (error) {
@@ -266,7 +266,8 @@
{
int error;
- assert(name && filter);
+ 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");
@@ -293,7 +294,7 @@
git_filter_def *fdef;
int error = 0;
- assert(name);
+ GIT_ASSERT_ARG(name);
/* cannot unregister default filters */
if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) {
@@ -618,7 +619,7 @@
{
size_t i;
- assert(name);
+ GIT_ASSERT_ARG(name);
if (!fl)
return 0;
@@ -639,7 +640,8 @@
git_filter_def *fdef = NULL;
git_filter_entry *fe;
- assert(fl && filter);
+ 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");
@@ -684,9 +686,8 @@
git_writestream *s, const char *buffer, size_t len)
{
struct buf_stream *buf_stream = (struct buf_stream *)s;
- assert(buf_stream);
-
- assert(buf_stream->complete == 0);
+ GIT_ASSERT_ARG(buf_stream);
+ GIT_ASSERT(buf_stream->complete == 0);
return git_buf_put(buf_stream->target, buffer, len);
}
@@ -694,9 +695,9 @@
static int buf_stream_close(git_writestream *s)
{
struct buf_stream *buf_stream = (struct buf_stream *)s;
- assert(buf_stream);
+ GIT_ASSERT_ARG(buf_stream);
- assert(buf_stream->complete == 0);
+ GIT_ASSERT(buf_stream->complete == 0);
buf_stream->complete = 1;
return 0;
@@ -725,8 +726,9 @@
struct buf_stream writer;
int error;
- git_buf_sanitize(tgt);
- git_buf_sanitize(src);
+ if ((error = git_buf_sanitize(tgt)) < 0 ||
+ (error = git_buf_sanitize(src)) < 0)
+ return error;
if (!filters) {
git_buf_attach_notowned(tgt, src->ptr, src->size);
@@ -739,7 +741,7 @@
&writer.parent)) < 0)
return error;
- assert(writer.complete);
+ GIT_ASSERT(writer.complete);
return error;
}
@@ -758,7 +760,7 @@
filters, repo, path, &writer.parent)) < 0)
return error;
- assert(writer.complete);
+ GIT_ASSERT(writer.complete);
return error;
}
@@ -789,7 +791,7 @@
filters, blob, &writer.parent)) < 0)
return error;
- assert(writer.complete);
+ GIT_ASSERT(writer.complete);
return error;
}
@@ -808,7 +810,7 @@
git_writestream *s, const char *buffer, size_t len)
{
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
- assert(proxy_stream);
+ GIT_ASSERT_ARG(proxy_stream);
return git_buf_put(&proxy_stream->input, buffer, len);
}
@@ -820,7 +822,7 @@
git_error_state error_state = {0};
int error;
- assert(proxy_stream);
+ GIT_ASSERT_ARG(proxy_stream);
error = proxy_stream->filter->apply(
proxy_stream->filter,
@@ -832,7 +834,9 @@
if (error == GIT_PASSTHROUGH) {
writebuf = &proxy_stream->input;
} else if (error == 0) {
- git_buf_sanitize(proxy_stream->output);
+ if ((error = git_buf_sanitize(proxy_stream->output)) < 0)
+ return error;
+
writebuf = proxy_stream->output;
} else {
/* close stream before erroring out taking care
@@ -853,11 +857,12 @@
static void proxy_stream_free(git_writestream *s)
{
struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
- assert(proxy_stream);
- git_buf_dispose(&proxy_stream->input);
- git_buf_dispose(&proxy_stream->temp_buf);
- git__free(proxy_stream);
+ if (proxy_stream) {
+ git_buf_dispose(&proxy_stream->input);
+ git_buf_dispose(&proxy_stream->temp_buf);
+ git__free(proxy_stream);
+ }
}
static int proxy_stream_init(
@@ -911,7 +916,7 @@
git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
git_writestream *filter_stream;
- assert(fe->filter->stream || fe->filter->apply);
+ GIT_ASSERT(fe->filter->stream || fe->filter->apply);
/* If necessary, create a stream that proxies the traditional
* application.
@@ -941,7 +946,7 @@
return error;
}
-void stream_list_free(git_vector *streams)
+static void filter_streams_free(git_vector *streams)
{
git_writestream *stream;
size_t i;
@@ -990,7 +995,7 @@
if (fd >= 0)
p_close(fd);
- stream_list_free(&filter_streams);
+ filter_streams_free(&filter_streams);
git_buf_dispose(&abspath);
return error;
}
@@ -1004,7 +1009,8 @@
git_writestream *stream_start;
int error, initialized = 0;
- git_buf_sanitize(data);
+ if ((error = git_buf_sanitize(data)) < 0)
+ return error;
if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
goto out;
@@ -1018,7 +1024,7 @@
if (initialized)
error |= stream_start->close(stream_start);
- stream_list_free(&filter_streams);
+ filter_streams_free(&filter_streams);
return error;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/futils.c cargo-0.51.0/debian/libgit2/src/futils.c
--- cargo-0.47.0/debian/libgit2/src/futils.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/futils.c 2021-04-07 03:36:48.000000000 +0000
@@ -7,8 +7,9 @@
#include "futils.h"
-#include "global.h"
+#include "runtime.h"
#include "strmap.h"
+#include "hash.h"
#include
#if GIT_WIN32
#include "win32/findfile.h"
@@ -184,7 +185,8 @@
git_buf buf = GIT_BUF_INIT;
git_oid checksum_new;
- assert(out && path && *path);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(path && *path);
if (updated != NULL)
*updated = 0;
@@ -492,7 +494,7 @@
goto done;
}
- assert(len);
+ GIT_ASSERT(len);
/*
* We've walked all the given path's parents and it's either relative
@@ -834,12 +836,12 @@
return error;
}
-int git_futils_fake_symlink(const char *old, const char *new)
+int git_futils_fake_symlink(const char *target, const char *path)
{
int retcode = GIT_ERROR;
- int fd = git_futils_creat_withpath(new, 0755, 0644);
+ int fd = git_futils_creat_withpath(path, 0755, 0644);
if (fd >= 0) {
- retcode = p_write(fd, old, strlen(old));
+ retcode = p_write(fd, target, strlen(target));
p_close(fd);
}
return retcode;
@@ -1127,8 +1129,6 @@
void git_futils_filestamp_set(
git_futils_filestamp *target, const git_futils_filestamp *source)
{
- assert(target);
-
if (source)
memcpy(target, source, sizeof(*target));
else
diff -Nru cargo-0.47.0/debian/libgit2/src/futils.h cargo-0.51.0/debian/libgit2/src/futils.h
--- cargo-0.47.0/debian/libgit2/src/futils.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/futils.h 2021-04-07 03:36:48.000000000 +0000
@@ -316,11 +316,11 @@
/**
* Create a "fake" symlink (text file containing the target path).
*
- * @param new symlink file to be created
- * @param old original symlink target
+ * @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 *new, const char *old);
+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
diff -Nru cargo-0.47.0/debian/libgit2/src/global.c cargo-0.51.0/debian/libgit2/src/global.c
--- cargo-0.47.0/debian/libgit2/src/global.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/global.c 1970-01-01 00:00:00.000000000 +0000
@@ -1,361 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * 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 "global.h"
-
-#include "alloc.h"
-#include "hash.h"
-#include "sysdir.h"
-#include "filter.h"
-#include "merge_driver.h"
-#include "streams/registry.h"
-#include "streams/mbedtls.h"
-#include "streams/openssl.h"
-#include "thread-utils.h"
-#include "git2/global.h"
-#include "transports/ssh.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-#include "win32/w32_stack.h"
-#include "win32/w32_crtdbg_stacktrace.h"
-#endif
-
-git_mutex git__mwindow_mutex;
-
-typedef int (*git_global_init_fn)(void);
-
-static git_global_init_fn git__init_callbacks[] = {
- git_allocator_global_init,
- git_hash_global_init,
- git_sysdir_global_init,
- git_filter_global_init,
- git_merge_driver_global_init,
- git_transport_ssh_global_init,
- git_stream_registry_global_init,
- git_openssl_stream_global_init,
- git_mbedtls_stream_global_init,
- git_mwindow_global_init
-};
-
-static git_global_shutdown_fn git__shutdown_callbacks[ARRAY_SIZE(git__init_callbacks)];
-
-static git_atomic git__n_shutdown_callbacks;
-static git_atomic git__n_inits;
-char *git__user_agent;
-char *git__ssl_ciphers;
-
-void git__on_shutdown(git_global_shutdown_fn callback)
-{
- int count = git_atomic_inc(&git__n_shutdown_callbacks);
- assert(count <= (int) ARRAY_SIZE(git__shutdown_callbacks) && count > 0);
- git__shutdown_callbacks[count - 1] = callback;
-}
-
-static void git__global_state_cleanup(git_global_st *st)
-{
- if (!st)
- return;
-
- git__free(st->error_t.message);
- st->error_t.message = NULL;
-}
-
-static int init_common(void)
-{
- size_t i;
- int ret;
-
- /* Initialize the CRT debug allocator first, before our first malloc */
-#if defined(GIT_MSVC_CRTDBG)
- git_win32__crtdbg_stacktrace_init();
- git_win32__stack_init();
-#endif
-
- /* Initialize subsystems that have global state */
- for (i = 0; i < ARRAY_SIZE(git__init_callbacks); i++)
- if ((ret = git__init_callbacks[i]()) != 0)
- break;
-
- GIT_MEMORY_BARRIER;
-
- return ret;
-}
-
-static void shutdown_common(void)
-{
- int pos;
-
- /* Shutdown subsystems that have registered */
- for (pos = git_atomic_get(&git__n_shutdown_callbacks);
- pos > 0;
- pos = git_atomic_dec(&git__n_shutdown_callbacks)) {
-
- git_global_shutdown_fn cb = git__swap(
- git__shutdown_callbacks[pos - 1], NULL);
-
- if (cb != NULL)
- cb();
- }
-
- git__free(git__user_agent);
- git__free(git__ssl_ciphers);
-}
-
-/**
- * Handle the global state with TLS
- *
- * If libgit2 is built with GIT_THREADS enabled,
- * the `git_libgit2_init()` function must be called
- * before calling any other function of the library.
- *
- * This function allocates a TLS index (using pthreads
- * or the native Win32 API) to store the global state
- * on a per-thread basis.
- *
- * Any internal method that requires global state will
- * then call `git__global_state()` which returns a pointer
- * to the global state structure; this pointer is lazily
- * allocated on each thread.
- *
- * Before shutting down the library, the
- * `git_libgit2_shutdown` method must be called to free
- * the previously reserved TLS index.
- *
- * If libgit2 is built without threading support, the
- * `git__global_statestate()` call returns a pointer to a single,
- * statically allocated global state. The `git_thread_`
- * functions are not available in that case.
- */
-
-/*
- * `git_libgit2_init()` allows subsystems to perform global setup,
- * which may take place in the global scope. An explicit memory
- * fence exists at the exit of `git_libgit2_init()`. Without this,
- * CPU cores are free to reorder cache invalidation of `_tls_init`
- * before cache invalidation of the subsystems' newly written global
- * state.
- */
-#if defined(GIT_THREADS) && defined(GIT_WIN32)
-
-static DWORD _fls_index;
-static volatile LONG _mutex = 0;
-
-static void WINAPI fls_free(void *st)
-{
- git__global_state_cleanup(st);
- git__free(st);
-}
-
-static int synchronized_threads_init(void)
-{
- int error;
-
- if ((_fls_index = FlsAlloc(fls_free)) == FLS_OUT_OF_INDEXES)
- return -1;
-
- git_threads_init();
-
- if (git_mutex_init(&git__mwindow_mutex))
- return -1;
-
- error = init_common();
-
- return error;
-}
-
-int git_libgit2_init(void)
-{
- int ret;
-
- /* Enter the lock */
- while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
-
- /* Only do work on a 0 -> 1 transition of the refcount */
- if ((ret = git_atomic_inc(&git__n_inits)) == 1) {
- if (synchronized_threads_init() < 0)
- ret = -1;
- }
-
- /* Exit the lock */
- InterlockedExchange(&_mutex, 0);
-
- return ret;
-}
-
-int git_libgit2_shutdown(void)
-{
- int ret;
-
- /* Enter the lock */
- while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
-
- /* Only do work on a 1 -> 0 transition of the refcount */
- if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
- shutdown_common();
-
- FlsFree(_fls_index);
- git_mutex_free(&git__mwindow_mutex);
-
-#if defined(GIT_MSVC_CRTDBG)
- git_win32__crtdbg_stacktrace_cleanup();
- git_win32__stack_cleanup();
-#endif
- }
-
- /* Exit the lock */
- InterlockedExchange(&_mutex, 0);
-
- return ret;
-}
-
-git_global_st *git__global_state(void)
-{
- git_global_st *ptr;
-
- assert(git_atomic_get(&git__n_inits) > 0);
-
- if ((ptr = FlsGetValue(_fls_index)) != NULL)
- return ptr;
-
- ptr = git__calloc(1, sizeof(git_global_st));
- if (!ptr)
- return NULL;
-
- git_buf_init(&ptr->error_buf, 0);
-
- FlsSetValue(_fls_index, ptr);
- return ptr;
-}
-
-#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
-
-static pthread_key_t _tls_key;
-static pthread_mutex_t _init_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_once_t _once_init = PTHREAD_ONCE_INIT;
-int init_error = 0;
-
-static void cb__free_status(void *st)
-{
- git__global_state_cleanup(st);
- git__free(st);
-}
-
-static void init_once(void)
-{
- if ((init_error = git_mutex_init(&git__mwindow_mutex)) != 0)
- return;
-
- pthread_key_create(&_tls_key, &cb__free_status);
-
- init_error = init_common();
-}
-
-int git_libgit2_init(void)
-{
- int ret, err;
-
- if ((err = pthread_mutex_lock(&_init_mutex)) != 0)
- return err;
-
- ret = git_atomic_inc(&git__n_inits);
- err = pthread_once(&_once_init, init_once);
- err |= pthread_mutex_unlock(&_init_mutex);
-
- if (err || init_error)
- return err | init_error;
-
- return ret;
-}
-
-int git_libgit2_shutdown(void)
-{
- void *ptr = NULL;
- pthread_once_t new_once = PTHREAD_ONCE_INIT;
- int error, ret;
-
- if ((error = pthread_mutex_lock(&_init_mutex)) != 0)
- return error;
-
- if ((ret = git_atomic_dec(&git__n_inits)) != 0)
- goto out;
-
- /* Shut down any subsystems that have global state */
- shutdown_common();
-
- ptr = pthread_getspecific(_tls_key);
- pthread_setspecific(_tls_key, NULL);
-
- git__global_state_cleanup(ptr);
- git__free(ptr);
-
- pthread_key_delete(_tls_key);
- git_mutex_free(&git__mwindow_mutex);
- _once_init = new_once;
-
-out:
- if ((error = pthread_mutex_unlock(&_init_mutex)) != 0)
- return error;
-
- return ret;
-}
-
-git_global_st *git__global_state(void)
-{
- git_global_st *ptr;
-
- assert(git_atomic_get(&git__n_inits) > 0);
-
- if ((ptr = pthread_getspecific(_tls_key)) != NULL)
- return ptr;
-
- ptr = git__calloc(1, sizeof(git_global_st));
- if (!ptr)
- return NULL;
-
- git_buf_init(&ptr->error_buf, 0);
- pthread_setspecific(_tls_key, ptr);
- return ptr;
-}
-
-#else
-
-static git_global_st __state;
-
-int git_libgit2_init(void)
-{
- int ret;
-
- /* Only init subsystems the first time */
- if ((ret = git_atomic_inc(&git__n_inits)) != 1)
- return ret;
-
- if ((ret = init_common()) < 0)
- return ret;
-
- return 1;
-}
-
-int git_libgit2_shutdown(void)
-{
- int ret;
-
- /* Shut down any subsystems that have global state */
- if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
- shutdown_common();
- git__global_state_cleanup(&__state);
- memset(&__state, 0, sizeof(__state));
- }
-
- return ret;
-}
-
-git_global_st *git__global_state(void)
-{
- return &__state;
-}
-
-#endif /* GIT_THREADS */
diff -Nru cargo-0.47.0/debian/libgit2/src/global.h cargo-0.51.0/debian/libgit2/src/global.h
--- cargo-0.47.0/debian/libgit2/src/global.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/global.h 1970-01-01 00:00:00.000000000 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This 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_global_h__
-#define INCLUDE_global_h__
-
-#include "common.h"
-
-#include "mwindow.h"
-#include "hash.h"
-
-typedef struct {
- git_error *last_error;
- git_error error_t;
- git_buf error_buf;
- char oid_fmt[GIT_OID_HEXSZ+1];
-
- /* On Windows, this is the current child thread that was started by
- * `git_thread_create`. This is used to set the thread's exit code
- * when terminated by `git_thread_exit`. It is unused on POSIX.
- */
- git_thread *current_thread;
-} git_global_st;
-
-git_global_st *git__global_state(void);
-
-extern git_mutex git__mwindow_mutex;
-
-#define GIT_GLOBAL (git__global_state())
-
-typedef void (*git_global_shutdown_fn)(void);
-
-extern void git__on_shutdown(git_global_shutdown_fn callback);
-
-extern const char *git_libgit2__user_agent(void);
-extern const char *git_libgit2__ssl_ciphers(void);
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/hash/sha1/collisiondetect.c cargo-0.51.0/debian/libgit2/src/hash/sha1/collisiondetect.c
--- cargo-0.47.0/debian/libgit2/src/hash/sha1/collisiondetect.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash/sha1/collisiondetect.c 2021-04-07 03:36:48.000000000 +0000
@@ -24,21 +24,21 @@
int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{
- assert(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)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
SHA1DCUpdate(&ctx->c, data, len);
return 0;
}
int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
if (SHA1DCFinal(out->id, &ctx->c)) {
git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected");
return -1;
diff -Nru cargo-0.47.0/debian/libgit2/src/hash/sha1/common_crypto.c cargo-0.51.0/debian/libgit2/src/hash/sha1/common_crypto.c
--- cargo-0.47.0/debian/libgit2/src/hash/sha1/common_crypto.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash/sha1/common_crypto.c 2021-04-07 03:36:48.000000000 +0000
@@ -26,7 +26,7 @@
int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
CC_SHA1_Init(&ctx->c);
return 0;
}
@@ -35,7 +35,7 @@
{
const unsigned char *data = _data;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
while (len > 0) {
CC_LONG chunk = (len > CC_LONG_MAX) ? CC_LONG_MAX : (CC_LONG)len;
@@ -51,7 +51,7 @@
int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
CC_SHA1_Final(out->id, &ctx->c);
return 0;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/hash/sha1/mbedtls.c cargo-0.51.0/debian/libgit2/src/hash/sha1/mbedtls.c
--- cargo-0.47.0/debian/libgit2/src/hash/sha1/mbedtls.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash/sha1/mbedtls.c 2021-04-07 03:36:48.000000000 +0000
@@ -19,28 +19,28 @@
void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
{
- assert(ctx);
- mbedtls_sha1_free(&ctx->c);
+ if (ctx)
+ mbedtls_sha1_free(&ctx->c);
}
int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{
- assert(ctx);
- mbedtls_sha1_init(&ctx->c);
- mbedtls_sha1_starts(&ctx->c);
- return 0;
+ 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)
{
- assert(ctx);
- mbedtls_sha1_update(&ctx->c, data, len);
- return 0;
+ GIT_ASSERT_ARG(ctx);
+ mbedtls_sha1_update(&ctx->c, data, len);
+ return 0;
}
int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{
- assert(ctx);
- mbedtls_sha1_finish(&ctx->c, out->id);
- return 0;
+ GIT_ASSERT_ARG(ctx);
+ mbedtls_sha1_finish(&ctx->c, out->id);
+ return 0;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/hash/sha1/openssl.c cargo-0.51.0/debian/libgit2/src/hash/sha1/openssl.c
--- cargo-0.47.0/debian/libgit2/src/hash/sha1/openssl.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash/sha1/openssl.c 2021-04-07 03:36:48.000000000 +0000
@@ -24,7 +24,7 @@
int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
if (SHA1_Init(&ctx->c) != 1) {
git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to initialize hash context");
@@ -36,7 +36,7 @@
int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
if (SHA1_Update(&ctx->c, data, len) != 1) {
git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to update hash");
@@ -48,7 +48,7 @@
int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
if (SHA1_Final(out->id, &ctx->c) != 1) {
git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash");
diff -Nru cargo-0.47.0/debian/libgit2/src/hash/sha1/win32.c cargo-0.51.0/debian/libgit2/src/hash/sha1/win32.c
--- cargo-0.47.0/debian/libgit2/src/hash/sha1/win32.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash/sha1/win32.c 2021-04-07 03:36:48.000000000 +0000
@@ -7,7 +7,7 @@
#include "win32.h"
-#include "global.h"
+#include "runtime.h"
#include
#include
@@ -129,7 +129,8 @@
if ((error = hash_cng_prov_init()) < 0)
error = hash_cryptoapi_prov_init();
- git__on_shutdown(sha1_shutdown);
+ if (!error)
+ error = git_runtime_shutdown_register(sha1_shutdown);
return error;
}
@@ -163,7 +164,7 @@
{
const BYTE *data = (BYTE *)_data;
- assert(ctx->ctx.cryptoapi.valid);
+ GIT_ASSERT(ctx->ctx.cryptoapi.valid);
while (len > 0) {
DWORD chunk = (len > MAXDWORD) ? MAXDWORD : (DWORD)len;
@@ -185,7 +186,7 @@
DWORD len = 20;
int error = 0;
- assert(ctx->ctx.cryptoapi.valid);
+ GIT_ASSERT(ctx->ctx.cryptoapi.valid);
if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0)) {
git_error_set(GIT_ERROR_OS, "legacy hash data could not be finished");
@@ -285,7 +286,7 @@
{
int error = 0;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
/*
* When compiled with GIT_THREADS, the global hash_prov data is
@@ -302,27 +303,30 @@
int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
{
- assert(ctx && ctx->type);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(ctx->type);
return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx);
}
int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
{
- assert(ctx && ctx->type);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(ctx->type);
return (ctx->type == CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, len);
}
int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx)
{
- assert(ctx && ctx->type);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(ctx->type);
return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
}
void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
{
- assert(ctx);
-
- if (ctx->type == CNG)
+ if (!ctx)
+ return;
+ else if (ctx->type == CNG)
hash_ctx_cng_cleanup(ctx);
else if(ctx->type == CRYPTOAPI)
hash_ctx_cryptoapi_cleanup(ctx);
diff -Nru cargo-0.47.0/debian/libgit2/src/hash.c cargo-0.51.0/debian/libgit2/src/hash.c
--- cargo-0.47.0/debian/libgit2/src/hash.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hash.c 2021-04-07 03:36:48.000000000 +0000
@@ -31,7 +31,7 @@
git_hash_sha1_ctx_cleanup(&ctx->sha1);
return;
default:
- assert(0);
+ /* unreachable */ ;
}
}
@@ -41,9 +41,10 @@
case GIT_HASH_ALGO_SHA1:
return git_hash_sha1_init(&ctx->sha1);
default:
- assert(0);
- return -1;
+ /* unreachable */ ;
}
+ GIT_ASSERT(0);
+ return -1;
}
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
@@ -52,9 +53,10 @@
case GIT_HASH_ALGO_SHA1:
return git_hash_sha1_update(&ctx->sha1, data, len);
default:
- assert(0);
- return -1;
+ /* unreachable */ ;
}
+ GIT_ASSERT(0);
+ return -1;
}
int git_hash_final(git_oid *out, git_hash_ctx *ctx)
@@ -63,9 +65,10 @@
case GIT_HASH_ALGO_SHA1:
return git_hash_sha1_final(out, &ctx->sha1);
default:
- assert(0);
- return -1;
+ /* unreachable */ ;
}
+ GIT_ASSERT(0);
+ return -1;
}
int git_hash_buf(git_oid *out, const void *data, size_t len)
@@ -80,7 +83,7 @@
error = git_hash_final(out, &ctx);
git_hash_ctx_cleanup(&ctx);
-
+
return error;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/hashsig.c cargo-0.51.0/debian/libgit2/src/hashsig.c
--- cargo-0.47.0/debian/libgit2/src/hashsig.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/hashsig.c 2021-04-07 03:36:48.000000000 +0000
@@ -133,13 +133,13 @@
uint8_t ignore_ch[256];
} hashsig_in_progress;
-static void hashsig_in_progress_init(
+static int hashsig_in_progress_init(
hashsig_in_progress *prog, git_hashsig *sig)
{
int i;
/* no more than one can be set */
- assert(!(sig->opt & GIT_HASHSIG_IGNORE_WHITESPACE) ||
+ GIT_ASSERT(!(sig->opt & GIT_HASHSIG_IGNORE_WHITESPACE) ||
!(sig->opt & GIT_HASHSIG_SMART_WHITESPACE));
if (sig->opt & GIT_HASHSIG_IGNORE_WHITESPACE) {
@@ -153,6 +153,8 @@
} else {
memset(prog, 0, sizeof(*prog));
}
+
+ return 0;
}
static int hashsig_add_hashes(
@@ -251,7 +253,8 @@
git_hashsig *sig = hashsig_alloc(opts);
GIT_ERROR_CHECK_ALLOC(sig);
- hashsig_in_progress_init(&prog, sig);
+ if ((error = hashsig_in_progress_init(&prog, sig)) < 0)
+ return error;
error = hashsig_add_hashes(sig, (const uint8_t *)buf, buflen, &prog);
@@ -283,7 +286,8 @@
return fd;
}
- hashsig_in_progress_init(&prog, sig);
+ if ((error = hashsig_in_progress_init(&prog, sig)) < 0)
+ return error;
while (!error) {
if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) {
@@ -318,7 +322,7 @@
{
int matches = 0, i, j, cmp;
- assert(a->cmp == b->cmp);
+ GIT_ASSERT_WITH_RETVAL(a->cmp == b->cmp, 0);
/* hash heaps are sorted - just look for overlap vs total */
@@ -354,9 +358,16 @@
/* 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)
+ if (a->mins.size < HASHSIG_HEAP_SIZE) {
return hashsig_heap_compare(&a->mins, &b->mins);
- else
- return (hashsig_heap_compare(&a->mins, &b->mins) +
- hashsig_heap_compare(&a->maxs, &b->maxs)) / 2;
+ } 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 -Nru cargo-0.47.0/debian/libgit2/src/idxmap.c cargo-0.51.0/debian/libgit2/src/idxmap.c
--- cargo-0.47.0/debian/libgit2/src/idxmap.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/idxmap.c 2021-04-07 03:36:48.000000000 +0000
@@ -138,28 +138,6 @@
return kh_val(map, idx);
}
-void git_idxmap_insert(git_idxmap *map, const git_index_entry *key, void *value, int *rval)
-{
- khiter_t idx = kh_put(idx, map, key, rval);
-
- if ((*rval) >= 0) {
- if ((*rval) == 0)
- kh_key(map, idx) = key;
- kh_val(map, idx) = value;
- }
-}
-
-void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, void *value, int *rval)
-{
- khiter_t idx = kh_put(idxicase, map, key, rval);
-
- if ((*rval) >= 0) {
- if ((*rval) == 0)
- kh_key(map, idx) = key;
- kh_val(map, idx) = value;
- }
-}
-
int git_idxmap_delete(git_idxmap *map, const git_index_entry *key)
{
khiter_t idx = kh_get(idx, map, key);
diff -Nru cargo-0.47.0/debian/libgit2/src/ignore.c cargo-0.51.0/debian/libgit2/src/ignore.c
--- cargo-0.47.0/debian/libgit2/src/ignore.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/ignore.c 2021-04-07 03:36:48.000000000 +0000
@@ -287,7 +287,9 @@
const char *workdir = git_repository_workdir(repo);
git_buf infopath = GIT_BUF_INIT;
- assert(repo && ignores && path);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(ignores);
+ GIT_ASSERT_ARG(path);
memset(ignores, 0, sizeof(*ignores));
ignores->repo = repo;
@@ -521,7 +523,9 @@
git_attr_file *file;
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
- assert(repo && ignored && pathname);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(ignored);
+ GIT_ASSERT_ARG(pathname);
workdir = git_repository_workdir(repo);
diff -Nru cargo-0.47.0/debian/libgit2/src/index.c cargo-0.51.0/debian/libgit2/src/index.c
--- cargo-0.47.0/debian/libgit2/src/index.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/index.c 2021-04-07 03:36:48.000000000 +0000
@@ -406,12 +406,13 @@
git_index *index;
int error = -1;
- assert(index_out);
+ GIT_ASSERT_ARG(index_out);
index = git__calloc(1, sizeof(git_index));
GIT_ERROR_CHECK_ALLOC(index);
- git_pool_init(&index->tree_pool, 1);
+ if (git_pool_init(&index->tree_pool, 1) < 0)
+ goto fail;
if (index_path != NULL) {
index->index_file_path = git__strdup(index_path);
@@ -460,7 +461,8 @@
/* index iterators increment the refcount of the index, so if we
* get here then there should be no outstanding iterators.
*/
- assert(!git_atomic_get(&index->readers));
+ if (git_atomic32_get(&index->readers))
+ return;
git_index_clear(index);
git_idxmap_free(index->entries_map);
@@ -486,14 +488,14 @@
/* call with locked index */
static void index_free_deleted(git_index *index)
{
- int readers = (int)git_atomic_get(&index->readers);
+ 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__swap(index->deleted.contents[i], NULL);
+ git_index_entry *ie = git_atomic_swap(index->deleted.contents[i], NULL);
index_entry_free(ie);
}
@@ -514,7 +516,7 @@
error = git_vector_remove(&index->entries, pos);
if (!error) {
- if (git_atomic_get(&index->readers) > 0) {
+ if (git_atomic32_get(&index->readers) > 0) {
error = git_vector_insert(&index->deleted, entry);
} else {
index_entry_free(entry);
@@ -530,7 +532,7 @@
{
int error = 0;
- assert(index);
+ GIT_ASSERT_ARG(index);
index->dirty = 1;
index->tree = NULL;
@@ -565,7 +567,7 @@
{
unsigned int old_ignore_case;
- assert(index);
+ GIT_ASSERT_ARG(index);
old_ignore_case = index->ignore_case;
@@ -777,14 +779,14 @@
unsigned git_index_version(git_index *index)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
return index->version;
}
int git_index_set_version(git_index *index, unsigned int version)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
if (version < INDEX_VERSION_NUMBER_LB ||
version > INDEX_VERSION_NUMBER_UB) {
@@ -813,9 +815,9 @@
return error;
}
-const char * git_index_path(const git_index *index)
+const char *git_index_path(const git_index *index)
{
- assert(index);
+ GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
return index->index_file_path;
}
@@ -823,7 +825,8 @@
{
git_repository *repo;
- assert(oid && index);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(index);
repo = INDEX_OWNER(index);
@@ -837,20 +840,25 @@
int git_index_write_tree_to(
git_oid *oid, git_index *index, git_repository *repo)
{
- assert(oid && index && 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)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
+
return index->entries.length;
}
const git_index_entry *git_index_get_byindex(
git_index *index, size_t n)
{
- assert(index);
+ GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
+
git_vector_sort(&index->entries);
return git_vector_get(&index->entries, n);
}
@@ -861,7 +869,7 @@
git_index_entry key = {{ 0 }};
git_index_entry *value;
- assert(index);
+ GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
key.path = path;
GIT_INDEX_ENTRY_STAGE_SET(&key, stage);
@@ -1038,23 +1046,24 @@
{
git_index_reuc_entry *reuc = NULL;
- assert(reuc_out && path);
+ 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) {
- assert(ancestor_oid);
+ GIT_ASSERT(ancestor_oid);
git_oid_cpy(&reuc->oid[0], ancestor_oid);
}
if ((reuc->mode[1] = our_mode) > 0) {
- assert(our_oid);
+ GIT_ASSERT(our_oid);
git_oid_cpy(&reuc->oid[1], our_oid);
}
if ((reuc->mode[2] = their_mode) > 0) {
- assert(their_oid);
+ GIT_ASSERT(their_oid);
git_oid_cpy(&reuc->oid[2], their_oid);
}
@@ -1346,7 +1355,8 @@
size_t path_length, position;
int error;
- assert(index && entry_ptr);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(entry_ptr);
entry = *entry_ptr;
@@ -1471,7 +1481,8 @@
int error = 0;
git_oid id;
- assert(index && source_entry->path);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(source_entry && source_entry->path);
if (INDEX_OWNER(index) == NULL)
return create_index_error(-1,
@@ -1556,7 +1567,8 @@
git_index_entry *entry = NULL;
int ret;
- assert(index && path);
+ 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);
@@ -1608,7 +1620,8 @@
{
int ret;
- assert(index && path);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(path);
if (((ret = git_index_remove(index, path, 0)) < 0 &&
ret != GIT_ENOTFOUND) ||
@@ -1628,7 +1641,7 @@
int error = 0;
size_t i;
- assert(index);
+ GIT_ASSERT_ARG(index);
if (!source_entries->length)
return 0;
@@ -1669,7 +1682,8 @@
git_index_entry *entry = NULL;
int ret;
- assert(index && source_entry && source_entry->path);
+ 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");
@@ -1757,7 +1771,8 @@
int git_index__find_pos(
size_t *out, git_index *index, const char *path, size_t path_len, int stage)
{
- assert(index && path);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(path);
return index_find(out, index, path, path_len, stage);
}
@@ -1765,7 +1780,8 @@
{
size_t pos;
- assert(index && path);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(path);
if (git_vector_bsearch2(
&pos, &index->entries, index->entries_search_path, path) < 0) {
@@ -1798,7 +1814,7 @@
unsigned short i;
int ret = 0;
- assert (index);
+ GIT_ASSERT_ARG(index);
if ((ancestor_entry &&
(ret = index_entry_dup(&entries[0], index, ancestor_entry)) < 0) ||
@@ -1869,7 +1885,10 @@
size_t count;
int stage, len = 0;
- assert(ancestor_out && our_out && their_out && index);
+ 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;
@@ -1915,7 +1934,11 @@
size_t pos;
int len = 0;
- assert(ancestor_out && our_out && their_out && index && path);
+ 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;
@@ -1962,13 +1985,14 @@
int git_index_conflict_remove(git_index *index, const char *path)
{
- assert(index && path);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(path);
return index_conflict_remove(index, path);
}
int git_index_conflict_cleanup(git_index *index)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
return index_conflict_remove(index, NULL);
}
@@ -1977,7 +2001,7 @@
size_t i;
git_index_entry *entry;
- assert(index);
+ GIT_ASSERT_ARG(index);
git_vector_foreach(&index->entries, i, entry) {
if (GIT_INDEX_ENTRY_STAGE(entry) > 0)
@@ -1994,7 +2018,8 @@
git_index_iterator *it;
int error;
- assert(iterator_out && index);
+ GIT_ASSERT_ARG(iterator_out);
+ GIT_ASSERT_ARG(index);
it = git__calloc(1, sizeof(git_index_iterator));
GIT_ERROR_CHECK_ALLOC(it);
@@ -2014,7 +2039,8 @@
const git_index_entry **out,
git_index_iterator *it)
{
- assert(out && it);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(it);
if (it->cur >= git_vector_length(&it->snap))
return GIT_ITEROVER;
@@ -2038,7 +2064,8 @@
{
git_index_conflict_iterator *it = NULL;
- assert(iterator_out && index);
+ GIT_ASSERT_ARG(iterator_out);
+ GIT_ASSERT_ARG(index);
it = git__calloc(1, sizeof(git_index_conflict_iterator));
GIT_ERROR_CHECK_ALLOC(it);
@@ -2058,7 +2085,10 @@
const git_index_entry *entry;
int len;
- assert(ancestor_out && our_out && their_out && iterator);
+ 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;
@@ -2096,14 +2126,14 @@
size_t git_index_name_entrycount(git_index *index)
{
- assert(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)
{
- assert(index);
+ GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
git_vector_sort(&index->names);
return git_vector_get(&index->names, n);
@@ -2124,7 +2154,7 @@
{
git_index_name_entry *conflict_name;
- assert((ancestor && ours) || (ancestor && theirs) || (ours && theirs));
+ 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);
@@ -2147,7 +2177,7 @@
size_t i;
git_index_name_entry *conflict_name;
- assert(index);
+ GIT_ASSERT_ARG(index);
git_vector_foreach(&index->names, i, conflict_name)
index_name_entry_free(conflict_name);
@@ -2161,7 +2191,7 @@
size_t git_index_reuc_entrycount(git_index *index)
{
- assert(index);
+ GIT_ASSERT_ARG(index);
return index->reuc.length;
}
@@ -2178,8 +2208,9 @@
{
int res;
- assert(index && reuc && reuc->path != NULL);
- assert(git_vector_is_sorted(&index->reuc));
+ 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;
@@ -2195,7 +2226,8 @@
git_index_reuc_entry *reuc = NULL;
int error = 0;
- assert(index && path);
+ 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 ||
@@ -2214,12 +2246,14 @@
git_index *index, const char *path)
{
size_t pos;
- assert(index && path);
+
+ GIT_ASSERT_ARG_WITH_RETVAL(index, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(path, NULL);
if (!index->reuc.length)
return NULL;
- assert(git_vector_is_sorted(&index->reuc));
+ GIT_ASSERT_WITH_RETVAL(git_vector_is_sorted(&index->reuc), NULL);
if (git_index_reuc_find(&pos, index, path) < 0)
return NULL;
@@ -2230,8 +2264,8 @@
const git_index_reuc_entry *git_index_reuc_get_byindex(
git_index *index, size_t n)
{
- assert(index);
- assert(git_vector_is_sorted(&index->reuc));
+ 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);
}
@@ -2241,7 +2275,8 @@
int error;
git_index_reuc_entry *reuc;
- assert(git_vector_is_sorted(&index->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);
@@ -2257,10 +2292,10 @@
{
size_t i;
- assert(index);
+ GIT_ASSERT_ARG(index);
for (i = 0; i < index->reuc.length; ++i)
- index_entry_reuc_free(git__swap(index->reuc.contents[i], NULL));
+ index_entry_reuc_free(git_atomic_swap(index->reuc.contents[i], NULL));
git_vector_clear(&index->reuc);
@@ -2625,7 +2660,7 @@
seek_forward(INDEX_HEADER_SIZE);
- assert(!index->entries.length);
+ GIT_ASSERT(!index->entries.length);
if ((error = index_map_resize(index->entries_map, header.entry_count, index->ignore_case)) < 0)
return error;
@@ -2744,7 +2779,7 @@
++same_len;
}
path_len -= same_len;
- varint_len = git_encode_varint(NULL, 0, same_len);
+ varint_len = git_encode_varint(NULL, 0, strlen(last) - same_len);
}
disk_size = index_entry_size(path_len, varint_len, entry->flags);
@@ -2780,23 +2815,26 @@
ondisk.flags = htons(entry->flags);
if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
+ const size_t path_offset = offsetof(struct entry_long, path);
struct entry_long ondisk_ext;
memcpy(&ondisk_ext, &ondisk, sizeof(struct entry_short));
ondisk_ext.flags_extended = htons(entry->flags_extended &
GIT_INDEX_ENTRY_EXTENDED_FLAGS);
- memcpy(mem, &ondisk_ext, offsetof(struct entry_long, path));
- path = ((struct entry_long*)mem)->path;
- disk_size -= offsetof(struct entry_long, path);
+ memcpy(mem, &ondisk_ext, path_offset);
+ path = (char *)mem + path_offset;
+ disk_size -= path_offset;
} else {
- memcpy(mem, &ondisk, offsetof(struct entry_short, path));
- path = ((struct entry_short*)mem)->path;
- disk_size -= offsetof(struct entry_short, path);
+ const size_t path_offset = offsetof(struct entry_short, path);
+ memcpy(mem, &ondisk, path_offset);
+ path = (char *)mem + path_offset;
+ disk_size -= path_offset;
}
if (last) {
varint_len = git_encode_varint((unsigned char *) path,
- disk_size, same_len);
- assert(varint_len > 0);
+ disk_size, strlen(last) - same_len);
+ GIT_ASSERT(varint_len > 0);
+
path += varint_len;
disk_size -= varint_len;
@@ -2804,14 +2842,14 @@
* If using path compression, we are not allowed
* to have additional trailing NULs.
*/
- assert(disk_size == path_len + 1);
+ 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.
*/
- assert(disk_size > path_len);
+ GIT_ASSERT(disk_size > path_len);
}
memcpy(path, path_start, path_len + 1);
@@ -3007,7 +3045,8 @@
bool is_extended;
uint32_t index_version_number;
- assert(index && file);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(file);
if (index->version <= INDEX_VERSION_NUMBER_EXT) {
is_extended = is_index_extended(index);
@@ -3158,7 +3197,7 @@
/* well, this isn't good */;
} else {
git_vector_swap(&entries, &index->entries);
- entries_map = git__swap(index->entries_map, entries_map);
+ entries_map = git_atomic_swap(index->entries_map, entries_map);
}
index->dirty = 1;
@@ -3189,7 +3228,7 @@
size_t i;
int error;
- assert((new_iterator->flags & GIT_ITERATOR_DONT_IGNORE_CASE));
+ 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 ||
@@ -3292,7 +3331,7 @@
goto done;
git_vector_swap(&new_entries, &index->entries);
- new_entries_map = git__swap(index->entries_map, new_entries_map);
+ new_entries_map = git_atomic_swap(index->entries_map, new_entries_map);
git_vector_foreach(&remove_entries, i, entry) {
if (index->tree)
@@ -3361,7 +3400,7 @@
git_pathspec ps;
bool no_fnmatch = (flags & GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH) != 0;
- assert(index);
+ GIT_ASSERT_ARG(index);
repo = INDEX_OWNER(index);
if ((error = git_repository__ensure_not_bare(repo, "index add all")) < 0)
@@ -3447,8 +3486,8 @@
payload,
};
- assert(index);
- assert(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(action == INDEX_ACTION_UPDATE || action == INDEX_ACTION_ADDALL);
repo = INDEX_OWNER(index);
@@ -3502,7 +3541,7 @@
const char *match;
git_buf path = GIT_BUF_INIT;
- assert(index);
+ GIT_ASSERT_ARG(index);
if ((error = git_pathspec__init(&ps, paths)) < 0)
return error;
@@ -3598,7 +3637,7 @@
GIT_REFCOUNT_INC(index);
- git_atomic_inc(&index->readers);
+ git_atomic32_inc(&index->readers);
git_vector_sort(&index->entries);
error = git_vector_dup(snap, &index->entries, index->entries._cmp);
@@ -3613,7 +3652,7 @@
{
git_vector_free(snap);
- git_atomic_dec(&index->readers);
+ git_atomic32_dec(&index->readers);
git_index_free(index);
}
@@ -3716,9 +3755,11 @@
/* 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 -Nru cargo-0.47.0/debian/libgit2/src/indexer.c cargo-0.51.0/debian/libgit2/src/indexer.c
--- cargo-0.47.0/debian/libgit2/src/indexer.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/indexer.c 2021-04-07 03:36:48.000000000 +0000
@@ -24,8 +24,6 @@
#include "zstream.h"
#include "object.h"
-extern git_mutex git__mwindow_mutex;
-
size_t git_indexer__max_objects = UINT32_MAX;
#define UINT31_MAX (0x7FFFFFFF)
@@ -123,10 +121,12 @@
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
int git_indexer_new(
git_indexer **out,
@@ -237,7 +237,8 @@
{
ssize_t read;
- assert(idx && stream);
+ GIT_ASSERT_ARG(idx);
+ GIT_ASSERT_ARG(stream);
do {
if ((read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf))) < 0)
@@ -260,15 +261,16 @@
{
git_mwindow *w = NULL;
- assert(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
+ GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA);
if (type == GIT_OBJECT_REF_DELTA) {
idx->off += GIT_OID_RAWSZ;
} else {
- off64_t base_off = get_delta_base(idx->pack, &w, &idx->off, type, idx->entry_start);
+ 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 (base_off < 0)
- return (int)base_off;
+ if (error < 0)
+ return error;
}
return 0;
@@ -279,7 +281,7 @@
{
ssize_t read;
- assert(stream);
+ GIT_ASSERT_ARG(stream);
do {
read = git_packfile_stream_read(stream, idx->objbuf, sizeof(idx->objbuf));
@@ -424,7 +426,10 @@
pentry = git__calloc(1, sizeof(struct git_pack_entry));
GIT_ERROR_CHECK_ALLOC(pentry);
- git_hash_final(&oid, &idx->hash_ctx);
+ if (git_hash_final(&oid, &idx->hash_ctx)) {
+ git__free(pentry);
+ goto on_error;
+ }
entry_size = idx->off - entry_start;
if (entry_start > UINT31_MAX) {
entry->offset = UINT32_MAX;
@@ -606,7 +611,8 @@
git_map map;
int error;
- assert(data && size);
+ GIT_ASSERT_ARG(data);
+ GIT_ASSERT_ARG(size);
if ((error = git__mmap_alignment(&mmap_alignment)) < 0)
return error;
@@ -671,7 +677,7 @@
return GIT_EBUFS;
if (!idx->have_stream) {
- error = git_packfile_unpack_header(&entry_size, &type, &idx->pack->mwf, &w, &idx->off);
+ error = git_packfile_unpack_header(&entry_size, &type, idx->pack, &w, &idx->off);
if (error == GIT_EBUFS) {
idx->off = entry_start;
return error;
@@ -753,7 +759,9 @@
struct git_pack_header *hdr = &idx->hdr;
git_mwindow_file *mwf = &idx->pack->mwf;
- assert(idx && data && stats);
+ GIT_ASSERT_ARG(idx);
+ GIT_ASSERT_ARG(data);
+ GIT_ASSERT_ARG(stats);
if ((error = append_to_pack(idx, data, size)) < 0)
return error;
@@ -807,7 +815,8 @@
/* 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 */
- git_mwindow_free_all(mwf);
+ 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) {
@@ -851,16 +860,16 @@
* 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 void seek_back_trailer(git_indexer *idx)
+static int seek_back_trailer(git_indexer *idx)
{
idx->pack->mwf.size -= GIT_OID_RAWSZ;
- git_mwindow_free_all(&idx->pack->mwf);
+ return git_mwindow_free_all(&idx->pack->mwf);
}
static int inject_object(git_indexer *idx, git_oid *id)
{
- git_odb_object *obj;
- struct entry *entry;
+ git_odb_object *obj = NULL;
+ struct entry *entry = NULL;
struct git_pack_entry *pentry = NULL;
git_oid foo = {{0}};
unsigned char hdr[64];
@@ -870,12 +879,14 @@
size_t len, hdr_len;
int error;
- seek_back_trailer(idx);
+ if ((error = seek_back_trailer(idx)) < 0)
+ goto cleanup;
+
entry_start = idx->pack->mwf.size;
- if (git_odb_read(&obj, idx->odb, id) < 0) {
+ if ((error = git_odb_read(&obj, idx->odb, id)) < 0) {
git_error_set(GIT_ERROR_INDEXER, "missing delta bases");
- return -1;
+ goto cleanup;
}
data = git_odb_object_data(obj);
@@ -887,8 +898,8 @@
entry->crc = crc32(0L, Z_NULL, 0);
/* Write out the object header */
- hdr_len = git_packfile__object_header(hdr, len, git_odb_object_type(obj));
- if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
+ 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;
@@ -944,7 +955,7 @@
unsigned int left = 0;
git_oid base;
- assert(git_vector_length(&idx->deltas) > 0);
+ 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");
@@ -957,7 +968,7 @@
continue;
curpos = delta->delta_off;
- error = git_packfile_unpack_header(&size, &type, &idx->pack->mwf, &w, &curpos);
+ error = git_packfile_unpack_header(&size, &type, idx->pack, &w, &curpos);
if (error < 0)
return error;
@@ -1075,7 +1086,9 @@
* hash_partially() keep the existing trailer out of the
* calculation.
*/
- git_mwindow_free_all(mwf);
+ 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);
@@ -1247,7 +1260,8 @@
if (git_filebuf_commit_at(&index_file, filename.ptr) < 0)
goto on_error;
- git_mwindow_free_all(&idx->pack->mwf);
+ if (git_mwindow_free_all(&idx->pack->mwf) < 0)
+ goto on_error;
/* Truncate file to undo rounding up to next page_size in append_to_pack */
if (p_ftruncate(idx->pack->mwf.fd, idx->pack->mwf.size) < 0) {
@@ -1317,13 +1331,7 @@
git_vector_free_deep(&idx->deltas);
- if (!git_mutex_lock(&git__mwindow_mutex)) {
- if (!idx->pack_committed)
- git_packfile_close(idx->pack, true);
-
- git_packfile_free(idx->pack);
- git_mutex_unlock(&git__mwindow_mutex);
- }
+ git_packfile_free(idx->pack, !idx->pack_committed);
iter = 0;
while (git_oidmap_iterate((void **) &value, idx->expected_oids, &iter, &key) == 0)
diff -Nru cargo-0.47.0/debian/libgit2/src/index.h cargo-0.51.0/debian/libgit2/src/index.h
--- cargo-0.47.0/debian/libgit2/src/index.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/index.h 2021-04-07 03:36:48.000000000 +0000
@@ -33,7 +33,7 @@
git_idxmap *entries_map;
git_vector deleted; /* deleted entries if readers > 0 */
- git_atomic readers; /* number of active iterators */
+ git_atomic32 readers; /* number of active iterators */
unsigned int on_disk:1;
unsigned int ignore_case:1;
diff -Nru cargo-0.47.0/debian/libgit2/src/integer.h cargo-0.51.0/debian/libgit2/src/integer.h
--- cargo-0.47.0/debian/libgit2/src/integer.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/integer.h 2021-04-07 03:36:48.000000000 +0000
@@ -77,6 +77,15 @@
# 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)
@@ -87,11 +96,17 @@
(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
/**
@@ -136,6 +151,68 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/iterator.c cargo-0.51.0/debian/libgit2/src/iterator.c
--- cargo-0.47.0/debian/libgit2/src/iterator.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/iterator.c 2021-04-07 03:36:48.000000000 +0000
@@ -330,7 +330,7 @@
break;
/* an exact match would have been matched by the bsearch above */
- assert(p[path_len]);
+ 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] == '/') {
@@ -678,14 +678,14 @@
return error;
}
-static void tree_iterator_frame_pop(tree_iterator *iter)
+static int tree_iterator_frame_pop(tree_iterator *iter)
{
tree_iterator_frame *frame;
git_buf *buf = NULL;
git_tree *tree;
size_t i;
- assert(iter->frames.size);
+ GIT_ASSERT(iter->frames.size);
frame = git_array_pop(iter->frames);
@@ -705,6 +705,8 @@
git_vector_free(&frame->similar_trees);
git_buf_dispose(&frame->path);
+
+ return 0;
}
static int tree_iterator_current(
@@ -760,7 +762,9 @@
/* no more entries in this frame. pop the frame out */
if (frame->next_idx == frame->entries.length) {
- tree_iterator_frame_pop(iter);
+ if ((error = tree_iterator_frame_pop(iter)) < 0)
+ break;
+
continue;
}
@@ -838,7 +842,7 @@
const git_index_entry **out, git_iterator *i)
{
tree_iterator *iter = (tree_iterator *)i;
- tree_iterator_frame *frame;
+ tree_iterator_frame *frame;
tree_iterator_entry *prev_entry;
int error;
@@ -855,7 +859,7 @@
* 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.
*/
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
if (prev_entry) {
if (!git_tree_entry__is_tree(prev_entry->tree_entry))
@@ -897,9 +901,8 @@
{
int error;
- git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry));
-
- if ((error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
+ 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;
@@ -974,7 +977,7 @@
tree_iterator_frame *frame;
tree_iterator_entry *entry;
- assert(i->type == GIT_ITERATOR_TREE);
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
iter = (tree_iterator *)i;
@@ -991,11 +994,11 @@
tree_iterator *iter;
tree_iterator_frame *frame;
- assert(i->type == GIT_ITERATOR_TREE);
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
iter = (tree_iterator *)i;
- assert(depth < iter->frames.size);
+ GIT_ASSERT(depth < iter->frames.size);
frame = &iter->frames.ptr[iter->frames.size-depth-1];
*parent_tree = frame->tree;
@@ -1376,7 +1379,8 @@
filesystem_iterator_entry_cmp)) < 0)
goto done;
- git_pool_init(&new_frame->entry_pool, 1);
+ 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);
@@ -1388,7 +1392,7 @@
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
goto done;
- assert(path_len > iter->root_len);
+ GIT_ASSERT(path_len > iter->root_len);
/* remove the prefix if requested */
path += iter->root_len;
@@ -1469,17 +1473,19 @@
return error;
}
-GIT_INLINE(void) filesystem_iterator_frame_pop(filesystem_iterator *iter)
+GIT_INLINE(int) filesystem_iterator_frame_pop(filesystem_iterator *iter)
{
filesystem_iterator_frame *frame;
- assert(iter->frames.size);
+ 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_free(&frame->entries);
+
+ return 0;
}
static void filesystem_iterator_set_current(
@@ -1646,7 +1652,7 @@
* 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.
*/
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
if (prev_entry) {
if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT &&
@@ -1762,12 +1768,13 @@
*out = NULL;
*status = GIT_ITERATOR_STATUS_NORMAL;
- assert(iterator__has_been_accessed(i));
+ GIT_ASSERT(iterator__has_been_accessed(i));
current_frame = filesystem_iterator_current_frame(iter);
- assert(current_frame);
+ GIT_ASSERT(current_frame);
+
current_entry = filesystem_iterator_current_entry(current_frame);
- assert(current_entry);
+ GIT_ASSERT(current_entry);
if ((error = git_iterator_current(&entry, i)) < 0)
return error;
@@ -2065,8 +2072,8 @@
static int index_iterator_skip_pseudotree(index_iterator *iter)
{
- assert(iterator__has_been_accessed(&iter->base));
- assert(S_ISDIR(iter->entry->mode));
+ GIT_ASSERT(iterator__has_been_accessed(&iter->base));
+ GIT_ASSERT(S_ISDIR(iter->entry->mode));
while (true) {
const git_index_entry *next_entry = NULL;
@@ -2280,10 +2287,11 @@
return i->cb->reset(i);
}
-void git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
+int git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
{
- assert(!iterator__has_been_accessed(i));
+ GIT_ASSERT(!iterator__has_been_accessed(i));
iterator_set_ignore_case(i, ignore_case);
+ return 0;
}
void git_iterator_free(git_iterator *iter)
diff -Nru cargo-0.47.0/debian/libgit2/src/iterator.h cargo-0.51.0/debian/libgit2/src/iterator.h
--- cargo-0.47.0/debian/libgit2/src/iterator.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/iterator.h 2021-04-07 03:36:48.000000000 +0000
@@ -263,7 +263,7 @@
return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0);
}
-extern void git_iterator_set_ignore_case(
+extern int git_iterator_set_ignore_case(
git_iterator *iter, bool ignore_case);
extern int git_iterator_current_tree_entry(
diff -Nru cargo-0.47.0/debian/libgit2/src/libgit2.c cargo-0.51.0/debian/libgit2/src/libgit2.c
--- cargo-0.47.0/debian/libgit2/src/libgit2.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/libgit2.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,379 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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 "libgit2.h"
+
+#include
+#include "alloc.h"
+#include "cache.h"
+#include "common.h"
+#include "filter.h"
+#include "hash.h"
+#include "index.h"
+#include "merge_driver.h"
+#include "pool.h"
+#include "mwindow.h"
+#include "object.h"
+#include "odb.h"
+#include "refs.h"
+#include "runtime.h"
+#include "sysdir.h"
+#include "thread.h"
+#include "threadstate.h"
+#include "git2/global.h"
+#include "streams/registry.h"
+#include "streams/mbedtls.h"
+#include "streams/openssl.h"
+#include "transports/smart.h"
+#include "transports/http.h"
+#include "transports/ssh.h"
+
+#ifdef GIT_WIN32
+# include "win32/w32_leakcheck.h"
+#endif
+
+#ifdef GIT_OPENSSL
+# include
+#endif
+
+#ifdef GIT_MBEDTLS
+# include
+#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 bool git_disable_pack_keep_file_checks;
+
+char *git__user_agent;
+char *git__ssl_ciphers;
+
+static void libgit2_settings_global_shutdown(void)
+{
+ git__free(git__user_agent);
+ git__free(git__ssl_ciphers);
+}
+
+static int git_libgit2_settings_global_init(void)
+{
+ return git_runtime_shutdown_register(libgit2_settings_global_shutdown);
+}
+
+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_threadstate_global_init,
+ git_threads_global_init,
+ git_hash_global_init,
+ git_sysdir_global_init,
+ git_filter_global_init,
+ git_merge_driver_global_init,
+ git_transport_ssh_global_init,
+ git_stream_registry_global_init,
+ git_openssl_stream_global_init,
+ git_mbedtls_stream_global_init,
+ git_mwindow_global_init,
+ git_pool_global_init,
+ git_libgit2_settings_global_init
+ };
+
+ return git_runtime_init(init_fns, ARRAY_SIZE(init_fns));
+}
+
+int git_libgit2_init_count(void)
+{
+ return git_runtime_init_count();
+}
+
+int git_libgit2_shutdown(void)
+{
+ return git_runtime_shutdown();
+}
+
+int git_libgit2_version(int *major, int *minor, int *rev)
+{
+ *major = LIBGIT2_VER_MAJOR;
+ *minor = LIBGIT2_VER_MINOR;
+ *rev = LIBGIT2_VER_REVISION;
+
+ return 0;
+}
+
+int git_libgit2_features(void)
+{
+ return 0
+#ifdef GIT_THREADS
+ | GIT_FEATURE_THREADS
+#endif
+#ifdef GIT_HTTPS
+ | GIT_FEATURE_HTTPS
+#endif
+#if defined(GIT_SSH)
+ | GIT_FEATURE_SSH
+#endif
+#if defined(GIT_USE_NSEC)
+ | GIT_FEATURE_NSEC
+#endif
+ ;
+}
+
+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_libgit2__user_agent(void)
+{
+ return git__user_agent;
+}
+
+const char *git_libgit2__ssl_ciphers(void)
+{
+ return git__ssl_ciphers;
+}
+
+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 *);
+ const git_buf *tmp;
+ int level;
+
+ if ((error = config_level_to_sysdir(&level, sysdir)) < 0 ||
+ (error = git_buf_sanitize(out)) < 0 ||
+ (error = git_sysdir_get(&tmp, level)) < 0)
+ break;
+
+ error = git_buf_sets(out, tmp->ptr);
+ }
+ 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 *);
+ const git_buf *tmp;
+
+ if ((error = git_buf_sanitize(out)) < 0 ||
+ (error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0)
+ break;
+
+ error = git_buf_sets(out, tmp->ptr);
+ }
+ 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 *);
+ if (file)
+ error = git_mbedtls__set_cert_location(file, 0);
+ if (error && path)
+ error = git_mbedtls__set_cert_location(path, 1);
+ }
+#else
+ git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations");
+ error = -1;
+#endif
+ break;
+ case GIT_OPT_SET_USER_AGENT:
+ git__free(git__user_agent);
+ git__user_agent = git__strdup(va_arg(ap, const char *));
+ if (!git__user_agent) {
+ git_error_set_oom();
+ error = -1;
+ }
+
+ 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_GET_USER_AGENT:
+ {
+ git_buf *out = va_arg(ap, git_buf *);
+ if ((error = git_buf_sanitize(out)) < 0)
+ break;
+ error = git_buf_sets(out, git__user_agent);
+ }
+ 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_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;
+
+ default:
+ git_error_set(GIT_ERROR_INVALID, "invalid option key");
+ error = -1;
+ }
+
+ va_end(ap);
+
+ return error;
+}
diff -Nru cargo-0.47.0/debian/libgit2/src/libgit2.h cargo-0.51.0/debian/libgit2/src/libgit2.h
--- cargo-0.47.0/debian/libgit2/src/libgit2.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/libgit2.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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_libgit2_h__
+#define INCLUDE_libgit2_h__
+
+extern int git_libgit2_init_count(void);
+
+extern const char *git_libgit2__user_agent(void);
+extern const char *git_libgit2__ssl_ciphers(void);
+
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/mailmap.c cargo-0.51.0/debian/libgit2/src/mailmap.c
--- cargo-0.47.0/debian/libgit2/src/mailmap.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/mailmap.c 2021-04-07 03:36:48.000000000 +0000
@@ -43,7 +43,8 @@
const git_mailmap_entry *b = (const git_mailmap_entry *)b_raw;
int cmp;
- assert(a && b && a->replace_email && b->replace_email);
+ 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)
@@ -185,7 +186,8 @@
git_mailmap_entry *entry = git__calloc(1, sizeof(git_mailmap_entry));
GIT_ERROR_CHECK_ALLOC(entry);
- assert(mm && replace_email && *replace_email);
+ 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);
@@ -290,7 +292,8 @@
git_buf content = GIT_BUF_INIT;
int error;
- assert(mm && repo);
+ GIT_ASSERT_ARG(mm);
+ GIT_ASSERT_ARG(repo);
error = git_revparse_single(&object, repo, rev);
if (error < 0)
@@ -350,8 +353,6 @@
const char *rev = NULL;
const char *path = NULL;
- assert(mm && repo);
-
/* If we're in a bare repo, default blob to 'HEAD:.mailmap' */
if (repo->is_bare)
rev = MM_BLOB_DEFAULT;
@@ -389,9 +390,14 @@
int git_mailmap_from_repository(git_mailmap **out, git_repository *repo)
{
- int error = git_mailmap_new(out);
- if (error < 0)
+ 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;
}
@@ -408,7 +414,7 @@
git_mailmap_entry needle = { NULL };
needle.replace_email = (char *)email;
- assert(email);
+ GIT_ASSERT_ARG_WITH_RETVAL(email, NULL);
if (!mm)
return NULL;
@@ -431,7 +437,8 @@
if (git__strcmp(entry->replace_email, email))
break; /* it's a different email, so we're done looking */
- assert(entry->replace_name); /* should be specific */
+ /* should be specific */
+ GIT_ASSERT_WITH_RETVAL(entry->replace_name, NULL);
if (!name || !git__strcmp(entry->replace_name, name))
return entry;
}
@@ -447,7 +454,9 @@
const char *name, const char *email)
{
const git_mailmap_entry *entry = NULL;
- assert(name && email);
+
+ GIT_ASSERT(name);
+ GIT_ASSERT(email);
*real_name = name;
*real_email = email;
diff -Nru cargo-0.47.0/debian/libgit2/src/map.h cargo-0.51.0/debian/libgit2/src/map.h
--- cargo-0.47.0/debian/libgit2/src/map.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/map.h 2021-04-07 03:36:48.000000000 +0000
@@ -36,9 +36,9 @@
} git_map;
#define GIT_MMAP_VALIDATE(out, len, prot, flags) do { \
- assert(out != NULL && len > 0); \
- assert((prot & GIT_PROT_WRITE) || (prot & GIT_PROT_READ)); \
- assert((flags & GIT_MAP_FIXED) == 0); } while (0)
+ 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);
diff -Nru cargo-0.47.0/debian/libgit2/src/merge.c cargo-0.51.0/debian/libgit2/src/merge.c
--- cargo-0.47.0/debian/libgit2/src/merge.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/merge.c 2021-04-07 03:36:48.000000000 +0000
@@ -68,9 +68,19 @@
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 */
-int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_repository *repo, size_t length, const git_oid input_array[])
+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;
@@ -129,7 +139,9 @@
git_commit_list *result = NULL;
int error = 0;
- assert(out && repo && input_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;
@@ -149,7 +161,9 @@
int error = 0;
git_array_oid_t array;
- assert(out && repo && input_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;
@@ -183,7 +197,9 @@
unsigned int i;
int error = -1;
- assert(out && repo && input_array);
+ 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");
@@ -571,7 +587,8 @@
git_oid oid;
int error = 0;
- assert(repo && cb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(cb);
if ((error = git_buf_joinpath(&merge_head_path, repo->gitdir,
GIT_MERGE_HEAD_FILE)) < 0)
@@ -640,7 +657,9 @@
git_index_entry const *result = NULL;
int error = 0;
- assert(resolved && diff_list && conflict);
+ GIT_ASSERT_ARG(resolved);
+ GIT_ASSERT_ARG(diff_list);
+ GIT_ASSERT_ARG(conflict);
*resolved = 0;
@@ -723,7 +742,9 @@
int ours_changed, theirs_changed;
int error = 0;
- assert(resolved && diff_list && conflict);
+ GIT_ASSERT_ARG(resolved);
+ GIT_ASSERT_ARG(diff_list);
+ GIT_ASSERT_ARG(conflict);
*resolved = 0;
@@ -763,7 +784,9 @@
git_index_entry *merged;
int error = 0;
- assert(resolved && diff_list && conflict);
+ GIT_ASSERT_ARG(resolved);
+ GIT_ASSERT_ARG(diff_list);
+ GIT_ASSERT_ARG(conflict);
*resolved = 0;
@@ -907,7 +930,9 @@
bool fallback = false;
int error;
- assert(resolved && diff_list && conflict);
+ GIT_ASSERT_ARG(resolved);
+ GIT_ASSERT_ARG(diff_list);
+ GIT_ASSERT_ARG(conflict);
*resolved = 0;
@@ -1027,6 +1052,9 @@
git_object_size_t blobsize;
int error;
+ if (*out || *out == &cache_invalid_marker)
+ return 0;
+
*out = NULL;
if ((error = git_blob_lookup(&blob, repo, &entry->id)) < 0)
@@ -1047,6 +1075,8 @@
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);
@@ -1069,18 +1099,16 @@
return 0;
/* update signature cache if needed */
- if (!cache[a_idx] && (error = index_entry_similarity_calc(&cache[a_idx], repo, a, opts)) < 0)
- return error;
- if (!cache[b_idx] && (error = index_entry_similarity_calc(&cache[b_idx], repo, b, opts)) < 0)
+ 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[b_idx])
+ 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)
+ if (opts->metric->similarity(&score, cache[a_idx], cache[b_idx], opts->metric->payload) < 0)
return -1;
/* clip score */
@@ -1504,7 +1532,8 @@
size_t src_count, tgt_count, i;
int error = 0;
- assert(diff_list && opts);
+ GIT_ASSERT_ARG(diff_list);
+ GIT_ASSERT_ARG(opts);
if ((opts->flags & GIT_MERGE_FIND_RENAMES) == 0)
return 0;
@@ -1550,7 +1579,7 @@
done:
if (cache != NULL) {
for (i = 0; i < cache_size; ++i) {
- if (cache[i] != NULL)
+ if (cache[i] != NULL && cache[i] != &cache_invalid_marker)
opts->metric->free_signature(cache[i], opts->metric->payload);
}
@@ -1797,12 +1826,12 @@
diff_list->repo = repo;
- git_pool_init(&diff_list->pool, 1);
- if (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);
+ 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;
}
@@ -1830,7 +1859,8 @@
git_config_entry *entry = NULL;
int error = 0;
- assert(repo && opts);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(opts);
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
@@ -2057,7 +2087,8 @@
size_t i;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -2141,7 +2172,8 @@
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error;
- assert(out && repo);
+ 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)) {
@@ -2428,7 +2460,8 @@
size_t i;
int error = 0;
- assert(repo && heads);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(heads);
if ((error = git_buf_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)
@@ -2456,7 +2489,7 @@
git_buf file_path = GIT_BUF_INIT;
int error = 0;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if ((error = git_buf_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)
@@ -2676,7 +2709,8 @@
char sep = 0;
int error = 0;
- assert(repo && heads);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(heads);
entries = git__calloc(heads_len, sizeof(struct merge_msg_entry));
GIT_ERROR_CHECK_ALLOC(entries);
@@ -2787,7 +2821,9 @@
{
int error = 0;
- assert (repo && our_head && heads);
+ 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 &&
@@ -2811,7 +2847,9 @@
size_t i, alloc_len;
int error = 0;
- assert(repo && our_head && their_heads);
+ 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));
@@ -2832,7 +2870,7 @@
return error;
}
-const char *merge_their_label(const char *branchname)
+static const char *merge_their_label(const char *branchname)
{
const char *slash;
@@ -3189,7 +3227,10 @@
int error = 0;
bool unborn;
- assert(analysis_out && preference_out && repo && their_heads && their_heads_len > 0);
+ 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");
@@ -3271,7 +3312,8 @@
unsigned int checkout_strategy;
int error = 0;
- assert(repo && their_heads && their_heads_len > 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");
@@ -3338,10 +3380,12 @@
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)
{
@@ -3350,10 +3394,12 @@
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)
@@ -3363,8 +3409,10 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/merge_driver.c cargo-0.51.0/debian/libgit2/src/merge_driver.c
--- cargo-0.47.0/debian/libgit2/src/merge_driver.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/merge_driver.c 2021-04-07 03:36:48.000000000 +0000
@@ -8,7 +8,7 @@
#include "merge_driver.h"
#include "vector.h"
-#include "global.h"
+#include "runtime.h"
#include "merge.h"
#include "git2/merge.h"
#include "git2/sys/merge.h"
@@ -32,33 +32,38 @@
static void git_merge_driver_global_shutdown(void);
-git_repository* git_merge_driver_source_repo(const git_merge_driver_source *src)
+git_repository *git_merge_driver_source_repo(
+ const git_merge_driver_source *src)
{
- assert(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)
+const git_index_entry *git_merge_driver_source_ancestor(
+ const git_merge_driver_source *src)
{
- assert(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)
+const git_index_entry *git_merge_driver_source_ours(
+ const git_merge_driver_source *src)
{
- assert(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)
+const git_index_entry *git_merge_driver_source_theirs(
+ const git_merge_driver_source *src)
{
- assert(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)
+const git_merge_file_options *git_merge_driver_source_file_options(
+ const git_merge_driver_source *src)
{
- assert(src);
+ GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
return src->file_opts;
}
@@ -209,7 +214,7 @@
merge_driver_name__binary, &git_merge_driver__binary)) < 0)
goto done;
- git__on_shutdown(git_merge_driver_global_shutdown);
+ error = git_runtime_shutdown_register(git_merge_driver_global_shutdown);
done:
if (error < 0)
@@ -262,7 +267,8 @@
{
int error;
- assert(name && driver);
+ 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");
diff -Nru cargo-0.47.0/debian/libgit2/src/merge_file.c cargo-0.51.0/debian/libgit2/src/merge_file.c
--- cargo-0.47.0/debian/libgit2/src/merge_file.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/merge_file.c 2021-04-07 03:36:48.000000000 +0000
@@ -28,7 +28,7 @@
#define GIT_MERGE_FILE_SIDE_EXISTS(X) ((X)->mode != 0)
-int git_merge_file__input_from_index(
+static int merge_file_input_from_index(
git_merge_file_input *input_out,
git_odb_object **odb_object_out,
git_odb *odb,
@@ -36,7 +36,10 @@
{
int error = 0;
- assert(input_out && odb_object_out && odb && entry);
+ 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;
@@ -241,7 +244,9 @@
{
git_merge_file_input inputs[3] = { {0} };
- assert(out && ours && theirs);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ours);
+ GIT_ASSERT_ARG(theirs);
memset(out, 0x0, sizeof(git_merge_file_result));
@@ -268,7 +273,10 @@
git_odb_object *odb_object[3] = { 0 };
int error = 0;
- assert(out && repo && ours && theirs);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(ours);
+ GIT_ASSERT_ARG(theirs);
memset(out, 0x0, sizeof(git_merge_file_result));
@@ -276,17 +284,15 @@
goto done;
if (ancestor) {
- if ((error = git_merge_file__input_from_index(
+ if ((error = merge_file_input_from_index(
&ancestor_input, &odb_object[0], odb, ancestor)) < 0)
goto done;
ancestor_ptr = &ancestor_input;
}
- if ((error = git_merge_file__input_from_index(
- &our_input, &odb_object[1], odb, ours)) < 0 ||
- (error = git_merge_file__input_from_index(
- &their_input, &odb_object[2], odb, theirs)) < 0)
+ if ((error = merge_file_input_from_index(&our_input, &odb_object[1], odb, ours)) < 0 ||
+ (error = merge_file_input_from_index(&their_input, &odb_object[2], odb, theirs)) < 0)
goto done;
error = merge_file__from_inputs(out,
diff -Nru cargo-0.47.0/debian/libgit2/src/message.c cargo-0.51.0/debian/libgit2/src/message.c
--- cargo-0.47.0/debian/libgit2/src/message.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/message.c 2021-04-07 03:36:48.000000000 +0000
@@ -28,8 +28,10 @@
int consecutive_empty_lines = 0;
size_t i, line_length, rtrimmed_line_length;
char *next_newline;
+ int error;
- git_buf_sanitize(message_out);
+ if ((error = git_buf_sanitize(message_out)) < 0)
+ return error;
for (i = 0; i < strlen(message); i += line_length) {
next_newline = memchr(message + i, '\n', message_len - i);
diff -Nru cargo-0.47.0/debian/libgit2/src/midx.c cargo-0.51.0/debian/libgit2/src/midx.c
--- cargo-0.47.0/debian/libgit2/src/midx.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/midx.c 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,482 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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 "buffer.h"
+#include "futils.h"
+#include "hash.h"
+#include "odb.h"
+#include "pack.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;
+};
+
+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)
+{
+ uint32_t i;
+ git_oid *oid, *prev_oid, zero_oid = {{0}};
+
+ 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 * GIT_OID_RAWSZ)
+ return midx_error("OID Lookup chunk has wrong length");
+
+ idx->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
+ prev_oid = &zero_oid;
+ for (i = 0; i < idx->num_objects; ++i, ++oid) {
+ if (git_oid_cmp(prev_oid, oid) >= 0)
+ return midx_error("OID Lookup index is non-monotonic");
+ prev_oid = oid;
+ }
+
+ 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;
+ git_oid idx_checksum = {{0}};
+ 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};
+
+ GIT_ASSERT_ARG(idx);
+
+ if (size < sizeof(struct git_midx_header) + GIT_OID_RAWSZ)
+ 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;
+ trailer_offset = size - GIT_OID_RAWSZ;
+ if (trailer_offset < last_chunk_offset)
+ return midx_error("wrong index size");
+ git_oid_cpy(&idx->checksum, (git_oid *)(data + trailer_offset));
+
+ if (git_hash_buf(&idx_checksum, data, (size_t)trailer_offset) < 0)
+ return midx_error("could not calculate signature");
+ if (!git_oid_equal(&idx_checksum, &idx->checksum))
+ return midx_error("index signature mismatch");
+
+ chunk_hdr = data + sizeof(struct git_midx_header);
+ last_chunk = NULL;
+ for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
+ chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 |
+ ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
+ 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 (ntohl(*((uint32_t *)(chunk_hdr + 0)))) {
+ 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:
+ return midx_error("unrecognized chunk ID");
+ }
+ }
+ 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_midx_file *idx;
+ git_file fd = -1;
+ size_t idx_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, "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);
+
+ error = git_buf_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;
+ git_oid idx_checksum = {{0}};
+
+ /* 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;
+ }
+
+ if (p_lseek(fd, -GIT_OID_RAWSZ, SEEK_END) < 0) {
+ p_close(fd);
+ return true;
+ }
+
+ bytes_read = p_read(fd, &idx_checksum, GIT_OID_RAWSZ);
+ p_close(fd);
+
+ if (bytes_read != GIT_OID_RAWSZ)
+ return true;
+
+ return git_oid_cmp(&idx_checksum, &idx->checksum) == 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;
+ uint32_t hi, lo;
+ const git_oid *current = NULL;
+ const unsigned char *object_offset;
+ off64_t offset;
+
+ GIT_ASSERT_ARG(idx);
+
+ 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_sha1(idx->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id);
+
+ if (pos >= 0) {
+ /* An object matching exactly the oid was found */
+ found = 1;
+ current = idx->oid_lookup + pos;
+ } 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;
+
+ if (!git_oid_ncmp(short_oid, current, len))
+ found = 1;
+ }
+ }
+
+ if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)idx->num_objects) {
+ /* Check for ambiguousity */
+ const git_oid *next = current + 1;
+
+ if (!git_oid_ncmp(short_oid, 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 (offset & 0x80000000) {
+ uint32_t object_large_offsets_pos = offset & 0x7fffffff;
+ 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_cpy(&e->sha1, current);
+ return 0;
+}
+
+int git_midx_foreach_entry(
+ git_midx_file *idx,
+ git_odb_foreach_cb cb,
+ void *data)
+{
+ size_t i;
+ int error;
+
+ GIT_ASSERT_ARG(idx);
+
+ for (i = 0; i < idx->num_objects; ++i) {
+ if ((error = cb(&idx->oid_lookup[i], 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_free(&idx->packfile_names);
+
+ return 0;
+}
+
+void git_midx_free(git_midx_file *idx)
+{
+ if (!idx)
+ return;
+
+ git_buf_dispose(&idx->filename);
+ git_midx_close(idx);
+ git__free(idx);
+}
diff -Nru cargo-0.47.0/debian/libgit2/src/midx.h cargo-0.51.0/debian/libgit2/src/midx.h
--- cargo-0.47.0/debian/libgit2/src/midx.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/midx.h 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 "map.h"
+#include "mwindow.h"
+#include "odb.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. */
+ git_oid *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 SHA1-checksum of the whole file. */
+ git_oid checksum;
+
+ /* something like ".git/objects/pack/multi-pack-index". */
+ git_buf 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;
+
+int git_midx_open(
+ git_midx_file **idx_out,
+ const char *path);
+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 -Nru cargo-0.47.0/debian/libgit2/src/mwindow.c cargo-0.51.0/debian/libgit2/src/mwindow.c
--- cargo-0.47.0/debian/libgit2/src/mwindow.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/mwindow.c 2021-04-07 03:36:48.000000000 +0000
@@ -10,7 +10,7 @@
#include "vector.h"
#include "futils.h"
#include "map.h"
-#include "global.h"
+#include "runtime.h"
#include "strmap.h"
#include "pack.h"
@@ -22,29 +22,43 @@
#define DEFAULT_MAPPED_LIMIT \
((1024 * 1024) * (sizeof(void*) >= 8 ? 8192ULL : 256UL))
+/* 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__pack_cache`. */
+git_mutex git__mwindow_mutex;
-/* Whenever you want to read or modify this, grab git__mwindow_mutex */
-static git_mwindow_ctl mem_ctl;
+/* 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_strmap *git__pack_cache = NULL;
-static void git_mwindow_files_free(void)
+static void git_mwindow_global_shutdown(void)
{
git_strmap *tmp = git__pack_cache;
+ git_mutex_free(&git__mwindow_mutex);
+
git__pack_cache = NULL;
git_strmap_free(tmp);
}
int git_mwindow_global_init(void)
{
- assert(!git__pack_cache);
+ int error;
+
+ GIT_ASSERT(!git__pack_cache);
- git__on_shutdown(git_mwindow_files_free);
- return git_strmap_new(&git__pack_cache);
+ if ((error = git_mutex_init(&git__mwindow_mutex)) < 0 ||
+ (error = git_strmap_new(&git__pack_cache)) < 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)
@@ -65,7 +79,7 @@
git__free(packname);
if (pack != NULL) {
- git_atomic_inc(&pack->refcount);
+ git_atomic32_inc(&pack->refcount);
git_mutex_unlock(&git__mwindow_mutex);
*out = pack;
return 0;
@@ -77,62 +91,51 @@
return error;
}
- git_atomic_inc(&pack->refcount);
+ git_atomic32_inc(&pack->refcount);
error = git_strmap_set(git__pack_cache, pack->pack_name, pack);
git_mutex_unlock(&git__mwindow_mutex);
-
if (error < 0) {
- git_packfile_free(pack);
- return -1;
+ git_packfile_free(pack, false);
+ return error;
}
*out = pack;
return 0;
}
-void git_mwindow_put_pack(struct git_pack_file *pack)
+int git_mwindow_put_pack(struct git_pack_file *pack)
{
- int count;
+ int count, error;
+ struct git_pack_file *pack_to_delete = NULL;
- if (git_mutex_lock(&git__mwindow_mutex) < 0)
- return;
+ if ((error = git_mutex_lock(&git__mwindow_mutex)) < 0)
+ return error;
/* put before get would be a corrupted state */
- assert(git__pack_cache);
+ GIT_ASSERT(git__pack_cache);
/* if we cannot find it, the state is corrupted */
- assert(git_strmap_exists(git__pack_cache, pack->pack_name));
+ GIT_ASSERT(git_strmap_exists(git__pack_cache, pack->pack_name));
- count = git_atomic_dec(&pack->refcount);
+ count = git_atomic32_dec(&pack->refcount);
if (count == 0) {
git_strmap_delete(git__pack_cache, pack->pack_name);
- git_packfile_free(pack);
+ pack_to_delete = pack;
}
-
git_mutex_unlock(&git__mwindow_mutex);
- return;
-}
+ git_packfile_free(pack_to_delete, false);
-void git_mwindow_free_all(git_mwindow_file *mwf)
-{
- if (git_mutex_lock(&git__mwindow_mutex)) {
- git_error_set(GIT_ERROR_THREAD, "unable to lock mwindow mutex");
- return;
- }
-
- git_mwindow_free_all_locked(mwf);
-
- git_mutex_unlock(&git__mwindow_mutex);
+ return 0;
}
/*
* Free all the windows in a sequence, typically because we're done
- * with the file
+ * with the file. Needs to hold the git__mwindow_mutex.
*/
-void git_mwindow_free_all_locked(git_mwindow_file *mwf)
+static int git_mwindow_free_all_locked(git_mwindow_file *mwf)
{
- git_mwindow_ctl *ctl = &mem_ctl;
+ git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
size_t i;
/*
@@ -152,7 +155,7 @@
while (mwf->windows) {
git_mwindow *w = mwf->windows;
- assert(w->inuse_cnt == 0);
+ GIT_ASSERT(w->inuse_cnt == 0);
ctl->mapped -= w->window_map.len;
ctl->open_windows--;
@@ -162,6 +165,24 @@
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;
}
/*
@@ -174,92 +195,152 @@
&& offset <= (off64_t)(win_off + win->window_map.len);
}
+#define GIT_MWINDOW__LRU -1
+#define GIT_MWINDOW__MRU 1
+
/*
- * Find the least-recently-used window in a file
+ * 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 void git_mwindow_scan_lru(
- git_mwindow_file *mwf,
- git_mwindow **lru_w,
- git_mwindow **lru_l)
-{
- git_mwindow *w, *w_l;
+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;
+ }
- for (w_l = NULL, w = mwf->windows; w; w = w->next) {
- if (!w->inuse_cnt) {
- /*
- * If the current one is more recent than the last one,
- * store it in the output parameter. If lru_w is NULL,
- * it's the first loop, so store it as well.
- */
- if (!*lru_w || w->last_used < (*lru_w)->last_used) {
- *lru_w = w;
- *lru_l = w_l;
- }
+ /*
+ * 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 == GIT_MWINDOW__LRU && lru_window->last_used > w->last_used) ||
+ (comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
+ lru_window = w;
+ lru_last = w_last;
+ found = true;
}
- w_l = w;
}
+
+ if (!found)
+ return false;
+
+ *out_window = lru_window;
+ if (out_last)
+ *out_last = lru_last;
+ return true;
}
/*
- * Close the least recently used window. You should check to see if
- * the file descriptors need closing from time to time. Called under
- * lock from new_window.
+ * 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(git_mwindow_file *mwf)
+static int git_mwindow_close_lru_window_locked(void)
{
- git_mwindow_ctl *ctl = &mem_ctl;
+ git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
+ git_mwindow_file *cur;
size_t i;
- git_mwindow *lru_w = NULL, *lru_l = NULL, **list = &mwf->windows;
+ git_mwindow *lru_window = NULL, *lru_last = NULL, **list = NULL;
- /* FIXME: Does this give us any advantage? */
- if(mwf->windows)
- git_mwindow_scan_lru(mwf, &lru_w, &lru_l);
-
- for (i = 0; i < ctl->windowfiles.length; ++i) {
- git_mwindow *last = lru_w;
- git_mwindow_file *cur = git_vector_get(&ctl->windowfiles, i);
- git_mwindow_scan_lru(cur, &lru_w, &lru_l);
- if (lru_w != last)
+ 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_w) {
+ if (!lru_window) {
git_error_set(GIT_ERROR_OS, "failed to close memory window; couldn't find LRU");
return -1;
}
- ctl->mapped -= lru_w->window_map.len;
- git_futils_mmap_free(&lru_w->window_map);
+ ctl->mapped -= lru_window->window_map.len;
+ git_futils_mmap_free(&lru_window->window_map);
- if (lru_l)
- lru_l->next = lru_w->next;
+ if (lru_last)
+ lru_last->next = lru_window->next;
else
- *list = lru_w->next;
+ *list = lru_window->next;
- git__free(lru_w);
+ 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_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(
- git_mwindow_file *mwf,
+static git_mwindow *new_window_locked(
git_file fd,
off64_t size,
off64_t offset)
{
- git_mwindow_ctl *ctl = &mem_ctl;
+ git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
size_t walign = git_mwindow__window_size / 2;
off64_t len;
git_mwindow *w;
- w = git__malloc(sizeof(*w));
+ w = git__calloc(1, sizeof(*w));
if (w == NULL)
return NULL;
- memset(w, 0x0, sizeof(*w));
w->offset = (offset / walign) * walign;
len = size - w->offset;
@@ -269,7 +350,7 @@
ctl->mapped += (size_t)len;
while (git_mwindow__mapped_limit < ctl->mapped &&
- git_mwindow_close_lru(mwf) == 0) /* nop */;
+ git_mwindow_close_lru_window_locked() == 0) /* nop */;
/*
* We treat `mapped_limit` as a soft limit. If we can't find a
@@ -283,7 +364,7 @@
* we're below our soft limits, so free up what we can and try again.
*/
- while (git_mwindow_close_lru(mwf) == 0)
+ while (git_mwindow_close_lru_window_locked() == 0)
/* nop */;
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) {
@@ -315,7 +396,7 @@
size_t extra,
unsigned int *left)
{
- git_mwindow_ctl *ctl = &mem_ctl;
+ git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
git_mwindow *w = *cursor;
if (git_mutex_lock(&git__mwindow_mutex)) {
@@ -339,7 +420,7 @@
* one.
*/
if (!w) {
- w = new_window(mwf, mwf->fd, mwf->size, offset);
+ w = new_window_locked(mwf->fd, mwf->size, offset);
if (w == NULL) {
git_mutex_unlock(&git__mwindow_mutex);
return NULL;
@@ -367,8 +448,11 @@
int git_mwindow_file_register(git_mwindow_file *mwf)
{
- git_mwindow_ctl *ctl = &mem_ctl;
- int ret;
+ 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");
@@ -376,20 +460,53 @@
}
if (ctl->windowfiles.length == 0 &&
- git_vector_init(&ctl->windowfiles, 8, NULL) < 0) {
+ (error = git_vector_init(&ctl->windowfiles, 8, NULL)) < 0) {
git_mutex_unlock(&git__mwindow_mutex);
- return -1;
+ goto cleanup;
}
- ret = git_vector_insert(&ctl->windowfiles, mwf);
+ 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 preferrable 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);
+ }
- return ret;
+cleanup:
+ git_vector_free(&closed_files);
+ return error;
}
void git_mwindow_file_deregister(git_mwindow_file *mwf)
{
- git_mwindow_ctl *ctl = &mem_ctl;
+ git_mwindow_ctl *ctl = &git_mwindow__mem_ctl;
git_mwindow_file *cur;
size_t i;
diff -Nru cargo-0.47.0/debian/libgit2/src/mwindow.h cargo-0.51.0/debian/libgit2/src/mwindow.h
--- cargo-0.47.0/debian/libgit2/src/mwindow.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/mwindow.h 2021-04-07 03:36:48.000000000 +0000
@@ -22,6 +22,7 @@
} git_mwindow;
typedef struct git_mwindow_file {
+ git_mutex lock; /* protects updates to fd */
git_mwindow *windows;
int fd;
off64_t size;
@@ -38,8 +39,7 @@
} git_mwindow_ctl;
int git_mwindow_contains(git_mwindow *win, off64_t offset);
-void git_mwindow_free_all(git_mwindow_file *mwf); /* locks */
-void git_mwindow_free_all_locked(git_mwindow_file *mwf); /* run under lock */
+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);
@@ -49,6 +49,6 @@
struct git_pack_file; /* just declaration to avoid cyclical includes */
int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
-void git_mwindow_put_pack(struct git_pack_file *pack);
+int git_mwindow_put_pack(struct git_pack_file *pack);
#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/net.c cargo-0.51.0/debian/libgit2/src/net.c
--- cargo-0.47.0/debian/libgit2/src/net.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/net.c 2021-04-07 03:36:48.000000000 +0000
@@ -14,7 +14,7 @@
#include "posix.h"
#include "buffer.h"
#include "http_parser.h"
-#include "global.h"
+#include "runtime.h"
#define DEFAULT_PORT_HTTP "80"
#define DEFAULT_PORT_HTTPS "443"
@@ -281,7 +281,8 @@
git_net_url tmp = GIT_NET_URL_INIT;
int error = 0;
- assert(url && redirect_location);
+ GIT_ASSERT(url);
+ GIT_ASSERT(redirect_location);
if (redirect_location[0] == '/') {
git__free(url->path);
@@ -336,7 +337,12 @@
int git_net_url_is_default_port(git_net_url *url)
{
- return (strcmp(url->port, default_port_for_scheme(url->scheme)) == 0);
+ const char *default_port;
+
+ if ((default_port = default_port_for_scheme(url->scheme)) != NULL)
+ return (strcmp(url->port, default_port) == 0);
+ else
+ return false;
}
void git_net_url_swap(git_net_url *a, git_net_url *b)
diff -Nru cargo-0.47.0/debian/libgit2/src/netops.c cargo-0.51.0/debian/libgit2/src/netops.c
--- cargo-0.47.0/debian/libgit2/src/netops.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/netops.c 2021-04-07 03:36:48.000000000 +0000
@@ -13,7 +13,7 @@
#include "posix.h"
#include "buffer.h"
#include "http_parser.h"
-#include "global.h"
+#include "runtime.h"
int gitno_recv(gitno_buffer *buf)
{
@@ -61,18 +61,20 @@
}
/* Consume up to ptr and move the rest of the buffer to the beginning */
-void gitno_consume(gitno_buffer *buf, const char *ptr)
+int gitno_consume(gitno_buffer *buf, const char *ptr)
{
size_t consumed;
- assert(ptr - buf->data >= 0);
- assert(ptr - buf->data <= (int) buf->len);
+ GIT_ASSERT(ptr - buf->data >= 0);
+ GIT_ASSERT(ptr - buf->data <= (int) buf->len);
consumed = ptr - buf->data;
memmove(buf->data, ptr, buf->offset - consumed);
memset(buf->data + buf->offset, 0x0, buf->len - buf->offset);
buf->offset -= consumed;
+
+ return 0;
}
/* Consume const bytes and move the rest of the buffer to the beginning */
diff -Nru cargo-0.47.0/debian/libgit2/src/netops.h cargo-0.51.0/debian/libgit2/src/netops.h
--- cargo-0.47.0/debian/libgit2/src/netops.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/netops.h 2021-04-07 03:36:48.000000000 +0000
@@ -62,7 +62,7 @@
void gitno_buffer_setup_callback(gitno_buffer *buf, char *data, size_t len, int (*recv)(gitno_buffer *buf), void *cb_data);
int gitno_recv(gitno_buffer *buf);
-void gitno_consume(gitno_buffer *buf, const char *ptr);
+int gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons);
#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/notes.c cargo-0.51.0/debian/libgit2/src/notes.c
--- cargo-0.47.0/debian/libgit2/src/notes.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/notes.c 2021-04-07 03:36:48.000000000 +0000
@@ -627,11 +627,11 @@
char *default_ref;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
- git_buf_sanitize(out);
-
- if ((error = note_get_default_ref(&default_ref, repo)) < 0)
+ if ((error = git_buf_sanitize(out)) < 0 ||
+ (error = note_get_default_ref(&default_ref, repo)) < 0)
return error;
git_buf_attach(out, default_ref, strlen(default_ref));
@@ -640,25 +640,25 @@
const git_signature *git_note_committer(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->committer;
}
const git_signature *git_note_author(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->author;
}
-const char * git_note_message(const git_note *note)
+const char *git_note_message(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->message;
}
-const git_oid * git_note_id(const git_note *note)
+const git_oid *git_note_id(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return ¬e->id;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/object.c cargo-0.51.0/debian/libgit2/src/object.c
--- cargo-0.47.0/debian/libgit2/src/object.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/object.c 2021-04-07 03:36:48.000000000 +0000
@@ -67,7 +67,7 @@
size_t object_size;
int error;
- assert(object_out);
+ GIT_ASSERT_ARG(object_out);
*object_out = NULL;
/* Validate type match */
@@ -86,11 +86,12 @@
GIT_ERROR_CHECK_ALLOC(object);
object->cached.flags = GIT_CACHE_STORE_PARSED;
object->cached.type = type;
- git_odb_hash(&object->cached.oid, data, size, type);
+ if ((error = git_odb_hash(&object->cached.oid, data, size, type)) < 0)
+ return error;
/* Parse raw object data */
def = &git_objects_table[type];
- assert(def->free && def->parse_raw);
+ GIT_ASSERT(def->free && def->parse_raw);
if ((error = def->parse_raw(object, data, size)) < 0) {
def->free(object);
@@ -114,7 +115,7 @@
git_object_def *def;
git_object *object = NULL;
- assert(object_out);
+ GIT_ASSERT_ARG(object_out);
*object_out = NULL;
/* Validate type match */
@@ -140,7 +141,7 @@
/* Parse raw object data */
def = &git_objects_table[odb_obj->cached.type];
- assert(def->free && def->parse);
+ GIT_ASSERT(def->free && def->parse);
if ((error = def->parse(object, odb_obj)) < 0)
def->free(object);
@@ -173,7 +174,9 @@
git_odb_object *odb_obj = NULL;
int error = 0;
- assert(repo && object_out && id);
+ 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");
@@ -210,7 +213,7 @@
} else if (cached->flags == GIT_CACHE_STORE_RAW) {
odb_obj = (git_odb_object *)cached;
} else {
- assert(!"Wrong caching type in the global object cache");
+ GIT_ASSERT(!"Wrong caching type in the global object cache");
}
} else {
/* Object was not found in the cache, let's explore the backends.
@@ -262,19 +265,19 @@
const git_oid *git_object_id(const git_object *obj)
{
- assert(obj);
+ GIT_ASSERT_ARG_WITH_RETVAL(obj, NULL);
return &obj->cached.oid;
}
git_object_t git_object_type(const git_object *obj)
{
- assert(obj);
+ GIT_ASSERT_ARG_WITH_RETVAL(obj, GIT_OBJECT_INVALID);
return obj->cached.type;
}
git_repository *git_object_owner(const git_object *obj)
{
- assert(obj);
+ GIT_ASSERT_ARG_WITH_RETVAL(obj, NULL);
return obj->repo;
}
@@ -395,9 +398,10 @@
git_object *source, *deref = NULL;
int error;
- assert(object && peeled);
+ GIT_ASSERT_ARG(object);
+ GIT_ASSERT_ARG(peeled);
- assert(target_type == GIT_OBJECT_TAG ||
+ GIT_ASSERT_ARG(target_type == GIT_OBJECT_TAG ||
target_type == GIT_OBJECT_COMMIT ||
target_type == GIT_OBJECT_TREE ||
target_type == GIT_OBJECT_BLOB ||
@@ -460,7 +464,9 @@
git_tree *tree = NULL;
git_tree_entry *entry = NULL;
- assert(out && treeish && path);
+ 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)
@@ -492,9 +498,12 @@
git_oid id = {{0}};
git_odb *odb;
- assert(out && obj);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(obj);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
- git_buf_sanitize(out);
repo = git_object_owner(obj);
if ((error = git_repository__configmap_lookup(&len, repo, GIT_CONFIGMAP_ABBREV)) < 0)
diff -Nru cargo-0.47.0/debian/libgit2/src/odb.c cargo-0.51.0/debian/libgit2/src/odb.c
--- cargo-0.47.0/debian/libgit2/src/odb.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/odb.c 2021-04-07 03:36:48.000000000 +0000
@@ -44,8 +44,8 @@
static git_cache *odb_cache(git_odb *odb)
{
- if (odb->rc.owner != NULL) {
- git_repository *owner = odb->rc.owner;
+ git_repository *owner = GIT_REFCOUNT_OWNER(odb);
+ if (owner != NULL) {
return &owner->objects;
}
@@ -114,7 +114,8 @@
size_t hdrlen;
int error;
- assert(id && obj);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(obj);
if (!git_object_typeisloose(obj->type)) {
git_error_set(GIT_ERROR_INVALID, "invalid object type");
@@ -346,7 +347,7 @@
{
git_rawobj raw;
- assert(id);
+ GIT_ASSERT_ARG(id);
raw.data = (void *)data;
raw.len = len;
@@ -376,7 +377,7 @@
{
fake_wstream *stream = (fake_wstream *)_stream;
- assert(stream->written + len <= stream->size);
+ GIT_ASSERT(stream->written + len <= stream->size);
memcpy(stream->buffer + stream->written, data, len);
stream->written += len;
@@ -449,12 +450,18 @@
git_odb *db = git__calloc(1, sizeof(*db));
GIT_ERROR_CHECK_ALLOC(db);
+ 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;
}
@@ -470,12 +477,13 @@
{
backend_internal *internal;
- assert(odb && backend);
+ 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 */
- assert(!backend->odb || backend->odb == odb);
+ GIT_ASSERT(!backend->odb || backend->odb == odb);
internal = git__malloc(sizeof(backend_internal));
GIT_ERROR_CHECK_ALLOC(internal);
@@ -485,13 +493,18 @@
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;
}
@@ -507,8 +520,19 @@
size_t git_odb_num_backends(git_odb *odb)
{
- assert(odb);
- return odb->backends.length;
+ 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)
@@ -522,17 +546,28 @@
int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos)
{
backend_internal *internal;
+ int error;
- assert(out && odb);
+ 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) {
- *out = internal->backend;
- return 0;
+ 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);
- git_error_set(GIT_ERROR_ODB, "no ODB backend loaded at index %" PRIuZ, pos);
- return GIT_ENOTFOUND;
+ return 0;
}
int git_odb__add_default_backends(
@@ -563,11 +598,18 @@
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)
+ if (backend->disk_inode == inode) {
+ git_mutex_unlock(&db->lock);
return 0;
+ }
}
+ git_mutex_unlock(&db->lock);
#endif
/* add the loose object backend */
@@ -645,7 +687,8 @@
{
git_odb *db;
- assert(out && objects_dir);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(objects_dir);
*out = NULL;
@@ -664,7 +707,7 @@
int git_odb__set_caps(git_odb *odb, int caps)
{
if (caps == GIT_ODB_CAP_FROM_OWNER) {
- git_repository *repo = odb->rc.owner;
+ git_repository *repo = GIT_REFCOUNT_OWNER(odb);
int val;
if (!repo) {
@@ -682,7 +725,12 @@
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;
@@ -691,9 +739,12 @@
git__free(internal);
}
+ if (locked)
+ git_mutex_unlock(&db->lock);
git_vector_free(&db->backends);
git_cache_dispose(&db->own_cache);
+ git_mutex_free(&db->lock);
git__memzero(db, sizeof(*db));
git__free(db);
@@ -714,7 +765,12 @@
{
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;
@@ -725,6 +781,7 @@
if (b->exists != NULL)
found = (bool)b->exists(b, id);
}
+ git_mutex_unlock(&db->lock);
return (int)found;
}
@@ -736,7 +793,12 @@
{
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;
@@ -749,13 +811,15 @@
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)
{
- assert(db && id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
if (odb_freshen_1(db, id, false))
return 1;
@@ -771,7 +835,8 @@
{
git_odb_object *object;
- assert(db && id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
if (git_oid_is_zero(id))
return 0;
@@ -798,6 +863,11 @@
int error = GIT_ENOTFOUND, num_found = 0;
git_oid last_found = {{0}}, 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;
@@ -811,18 +881,23 @@
error = b->exists_prefix(&found, b, key, len);
if (error == GIT_ENOTFOUND || error == GIT_PASSTHROUGH)
continue;
- if (error)
+ 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))
+ 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;
@@ -839,7 +914,8 @@
int error;
git_oid key = {{0}};
- assert(db && short_id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(short_id);
if (len < GIT_OID_MINPREFIXLEN)
return git_odb__error_ambiguous("prefix length too short");
@@ -875,7 +951,8 @@
{
size_t i;
- assert(db && ids);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(ids);
for (i = 0; i < count; i++) {
git_odb_expand_id *query = &ids[i];
@@ -962,6 +1039,10 @@
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;
@@ -983,9 +1064,11 @@
case GIT_ENOTFOUND:
break;
default:
+ git_mutex_unlock(&db->lock);
return error;
}
}
+ git_mutex_unlock(&db->lock);
return passthrough ? GIT_PASSTHROUGH : GIT_ENOTFOUND;
}
@@ -997,7 +1080,11 @@
int error = GIT_ENOTFOUND;
git_odb_object *object;
- assert(db && id && out && len_p && type_p);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(len_p);
+ GIT_ASSERT_ARG(type_p);
*out = NULL;
@@ -1054,6 +1141,10 @@
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;
@@ -1066,12 +1157,15 @@
if (error == GIT_PASSTHROUGH || error == GIT_ENOTFOUND)
continue;
- if (error < 0)
+ if (error < 0) {
+ git_mutex_unlock(&db->lock);
return error;
+ }
found = true;
}
}
+ git_mutex_unlock(&db->lock);
if (!found)
return GIT_ENOTFOUND;
@@ -1104,7 +1198,9 @@
{
int error;
- assert(out && db && id);
+ 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");
@@ -1162,6 +1258,10 @@
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;
@@ -1178,8 +1278,10 @@
continue;
}
- if (error)
+ if (error) {
+ git_mutex_unlock(&db->lock);
goto out;
+ }
git__free(data);
data = raw.data;
@@ -1194,6 +1296,7 @@
error = git_odb__error_ambiguous(buf.ptr);
git_buf_dispose(&buf);
+ git_mutex_unlock(&db->lock);
goto out;
}
@@ -1201,6 +1304,7 @@
found = true;
}
}
+ git_mutex_unlock(&db->lock);
if (!found)
return GIT_ENOTFOUND;
@@ -1237,7 +1341,8 @@
git_oid key = {{0}};
int error;
- assert(out && db);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(db);
if (len < GIT_OID_MINPREFIXLEN)
return git_odb__error_ambiguous("prefix length too short");
@@ -1267,28 +1372,46 @@
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(&db->backends, i, internal) {
+ git_vector_foreach(&backends, i, internal) {
git_odb_backend *b = internal->backend;
- int error = b->foreach(b, cb, payload);
+ error = b->foreach(b, cb, payload);
if (error != 0)
- return error;
+ goto cleanup;
}
- return 0;
+cleanup:
+ git_vector_free(&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_ERROR;
+ int error;
git_odb_stream *stream;
- assert(oid && db);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(db);
- git_odb_hash(oid, data, len, type);
+ if ((error = git_odb_hash(oid, data, len, type)) < 0)
+ return error;
if (git_oid_is_zero(oid))
return error_null_oid(GIT_EINVALID, "cannot write object");
@@ -1296,7 +1419,11 @@
if (git_odb__freshen(db, oid))
return 0;
- for (i = 0; i < db->backends.length && error < 0; ++i) {
+ 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;
@@ -1307,6 +1434,7 @@
if (b->write != NULL)
error = b->write(b, oid, data, len, type);
}
+ git_mutex_unlock(&db->lock);
if (!error || error == GIT_PASSTHROUGH)
return 0;
@@ -1345,8 +1473,14 @@
int error = GIT_ERROR;
git_hash_ctx *ctx = NULL;
- assert(stream && db);
+ 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;
@@ -1363,6 +1497,7 @@
error = init_fake_wstream(stream, b, size, type);
}
}
+ git_mutex_unlock(&db->lock);
if (error < 0) {
if (error == GIT_PASSTHROUGH)
@@ -1455,8 +1590,14 @@
size_t i, reads = 0;
int error = GIT_ERROR;
- assert(stream && db);
+ 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;
@@ -1466,6 +1607,7 @@
error = b->readstream(stream, len, type, b, oid);
}
}
+ git_mutex_unlock(&db->lock);
if (error == GIT_PASSTHROUGH)
error = 0;
@@ -1480,8 +1622,14 @@
size_t i, writes = 0;
int error = GIT_ERROR;
- assert(out && db);
+ 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;
@@ -1495,6 +1643,7 @@
error = b->writepack(out, b, db, progress_cb, progress_payload);
}
}
+ git_mutex_unlock(&db->lock);
if (error == GIT_PASSTHROUGH)
error = 0;
@@ -1510,10 +1659,12 @@
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)
{
@@ -1524,18 +1675,27 @@
int git_odb_refresh(struct git_odb *db)
{
size_t i;
- assert(db);
+ 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)
+ if (error < 0) {
+ git_mutex_unlock(&db->lock);
return error;
+ }
}
}
+ git_mutex_unlock(&db->lock);
return 0;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/odb.h cargo-0.51.0/debian/libgit2/src/odb.h
--- cargo-0.47.0/debian/libgit2/src/odb.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/odb.h 2021-04-07 03:36:48.000000000 +0000
@@ -40,6 +40,7 @@
/* EXPORT */
struct git_odb {
git_refcount rc;
+ git_mutex lock; /* protects backends */
git_vector backends;
git_cache own_cache;
unsigned int do_fsync :1;
diff -Nru cargo-0.47.0/debian/libgit2/src/odb_loose.c cargo-0.51.0/debian/libgit2/src/odb_loose.c
--- cargo-0.47.0/debian/libgit2/src/odb_loose.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/odb_loose.c 2021-04-07 03:36:48.000000000 +0000
@@ -304,12 +304,12 @@
* (including the initial sequence in the head buffer).
*/
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) ||
- (body = git__malloc(alloc_size)) == NULL) {
+ (body = git__calloc(1, alloc_size)) == NULL) {
error = -1;
goto done;
}
- assert(decompressed >= head_len);
+ GIT_ASSERT(decompressed >= head_len);
body_len = decompressed - head_len;
if (body_len)
@@ -344,7 +344,8 @@
int error;
git_buf obj = GIT_BUF_INIT;
- assert(out && loc);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(loc);
if (git_buf_oom(loc))
return -1;
@@ -386,8 +387,8 @@
git_rawobj *out, const unsigned char *data, size_t len)
{
git_zstream zs = GIT_ZSTREAM_INIT;
- obj_hdr hdr;
- unsigned char inflated[MAX_HEADER_LEN];
+ obj_hdr hdr = {0};
+ unsigned char inflated[MAX_HEADER_LEN] = {0};
size_t header_len, inflated_len = sizeof(inflated);
int error;
@@ -411,7 +412,8 @@
ssize_t obj_len;
int fd, error;
- assert(out && loc);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(loc);
if (git_buf_oom(loc))
return -1;
@@ -585,7 +587,8 @@
git_rawobj raw;
int error;
- assert(backend && oid);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(oid);
raw.len = 0;
raw.type = GIT_OBJECT_INVALID;
@@ -609,7 +612,8 @@
git_rawobj raw;
int error = 0;
- assert(backend && oid);
+ 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",
@@ -636,7 +640,7 @@
{
int error = 0;
- assert(len >= GIT_OID_MINPREFIXLEN && len <= GIT_OID_HEXSZ);
+ GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN && len <= GIT_OID_HEXSZ);
if (len == GIT_OID_HEXSZ) {
/* We can fall back to regular read method */
@@ -647,7 +651,7 @@
git_buf object_path = GIT_BUF_INIT;
git_rawobj raw;
- assert(backend && short_oid);
+ GIT_ASSERT_ARG(backend && short_oid);
if ((error = locate_object_short_oid(&object_path, out_oid,
(loose_backend *)backend, short_oid, len)) == 0 &&
@@ -669,7 +673,8 @@
git_buf object_path = GIT_BUF_INIT;
int error;
- assert(backend && oid);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(oid);
error = locate_object(&object_path, (loose_backend *)backend, oid);
@@ -684,7 +689,10 @@
git_buf object_path = GIT_BUF_INIT;
int error;
- assert(backend && out && short_id && len >= GIT_OID_MINPREFIXLEN);
+ 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);
@@ -759,7 +767,8 @@
struct foreach_state state;
loose_backend *backend = (loose_backend *) _backend;
- assert(backend && cb);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(cb);
objects_dir = backend->objects_dir;
@@ -833,7 +842,7 @@
size_t hdrlen;
int error;
- assert(_backend);
+ GIT_ASSERT_ARG(_backend);
backend = (loose_backend *)_backend;
*stream_out = NULL;
@@ -991,7 +1000,11 @@
obj_hdr hdr;
int error = 0;
- assert(stream_out && len_out && type_out && _backend && oid);
+ 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;
@@ -1108,11 +1121,7 @@
static void loose_backend__free(git_odb_backend *_backend)
{
- loose_backend *backend;
- assert(_backend);
- backend = (loose_backend *)_backend;
-
- git__free(backend);
+ git__free(_backend);
}
int git_odb_backend_loose(
@@ -1126,7 +1135,8 @@
loose_backend *backend;
size_t objects_dirlen, alloclen;
- assert(backend_out && objects_dir);
+ GIT_ASSERT_ARG(backend_out);
+ GIT_ASSERT_ARG(objects_dir);
objects_dirlen = strlen(objects_dir);
diff -Nru cargo-0.47.0/debian/libgit2/src/odb_mempack.c cargo-0.51.0/debian/libgit2/src/odb_mempack.c
--- cargo-0.47.0/debian/libgit2/src/odb_mempack.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/odb_mempack.c 2021-04-07 03:36:48.000000000 +0000
@@ -110,6 +110,8 @@
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];
@@ -154,7 +156,7 @@
{
struct memory_packer_db *db;
- assert(out);
+ GIT_ASSERT_ARG(out);
db = git__calloc(1, sizeof(struct memory_packer_db));
GIT_ERROR_CHECK_ALLOC(db);
diff -Nru cargo-0.47.0/debian/libgit2/src/odb_pack.c cargo-0.51.0/debian/libgit2/src/odb_pack.c
--- cargo-0.47.0/debian/libgit2/src/odb_pack.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/odb_pack.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,11 +11,12 @@
#include "git2/repository.h"
#include "git2/indexer.h"
#include "git2/sys/odb_backend.h"
+#include "delta.h"
#include "futils.h"
#include "hash.h"
-#include "odb.h"
-#include "delta.h"
+#include "midx.h"
#include "mwindow.h"
+#include "odb.h"
#include "pack.h"
#include "git2/odb_backend.h"
@@ -25,6 +26,8 @@
struct pack_backend {
git_odb_backend parent;
+ git_midx_file *midx;
+ git_vector midx_packs;
git_vector packs;
struct git_pack_file *last_found;
char *pack_folder;
@@ -47,36 +50,43 @@
* 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 preload all the known packfiles in the ODB.
+ * # 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.
* |
- * |-# packfile_load_all
- * | Tries to find the `pack` folder, if it exists. ODBs without
- * | a pack folder are ignored altogether. If there's a `pack` folder
- * | we run a `dirent` callback through every file in the pack folder
- * | to find our packfiles. The packfiles are then sorted according
- * | to a sorting callback.
- * |
- * |-# 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.
- * | |
- * | |-# packfile_check
- * | 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.
+ * |-# 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.
*
*
*
@@ -84,48 +94,66 @@
* A standard packed `exist` query for an OID
* --------------------------------------------------
*
- * # pack_backend__exists
- * | Check if the given SHA1 oid exists in any of the packs
- * | that have been loaded for our ODB.
+ * # pack_backend__exists / pack_backend__exists_prefix
+ * | Check if the given SHA1 oid (or a SHA1 oid prefix) exists in any of the
+ * | packs that have been loaded for our ODB.
* |
- * |-# pack_entry_find
- * | Iterate through all the 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.
- * |
- * |-# pack_entry_find1
- * | Check the index of an individual pack to see if the SHA1
- * | OID can be found. If we can find the offset to that SHA1
- * | 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 behing 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.
- * |
- * |-# packfile_open
- * See `packfile_open` in Chapter 3
+ * |-# pack_entry_find / pack_entry_find_prefix
+ * | If there is a multi-pack-index present, search the SHA1 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 SHA1 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 SHA1
+ * | OID can be found. If we can find the offset to that SHA1 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 behing 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
* --------------------------------------------------
- * TODO
+ *
+ * # pack_backend__read / pack_backend__read_prefix
+ * | Check if the given SHA1 oid (or a SHA1 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 SHA1 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.
*
*/
@@ -140,6 +168,8 @@
static int packfile_load__cb(void *_data, git_buf *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);
@@ -163,6 +193,14 @@
*
***********************************************************/
+static int packfile_byname_search_cmp(const void *path_, const void *p_)
+{
+ const git_buf *path = (const git_buf *)path_;
+ const struct git_pack_file *p = (const struct git_pack_file *)p_;
+
+ return strncmp(p->pack_name, git_buf_cstr(path), git_buf_len(path));
+}
+
static int packfile_sort__cb(const void *a_, const void *b_)
{
const struct git_pack_file *a = a_;
@@ -198,20 +236,20 @@
struct pack_backend *backend = data;
struct git_pack_file *pack;
const char *path_str = git_buf_cstr(path);
- size_t i, cmp_len = git_buf_len(path);
+ git_buf index_prefix = GIT_BUF_INIT;
+ size_t cmp_len = git_buf_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_buf_attach_notowned(&index_prefix, path_str, cmp_len);
- for (i = 0; i < backend->packs.length; ++i) {
- struct git_pack_file *p = git_vector_get(&backend->packs, i);
-
- if (strncmp(p->pack_name, path_str, cmp_len) == 0)
- return 0;
- }
+ 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);
@@ -228,22 +266,26 @@
}
-static int pack_entry_find_inner(
- struct git_pack_entry *e,
- struct pack_backend *backend,
- const git_oid *oid,
- struct git_pack_file *last_found)
+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 i;
+ if (backend->midx &&
+ git_midx_entry_find(&midx_entry, backend->midx, oid, GIT_OID_HEXSZ) == 0 &&
+ midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
+ e->offset = midx_entry.offset;
+ git_oid_cpy(&e->sha1, &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, GIT_OID_HEXSZ) == 0)
return 0;
- for (i = 0; i < backend->packs.length; ++i) {
- struct git_pack_file *p;
-
- p = git_vector_get(&backend->packs, i);
+ git_vector_foreach(&backend->packs, i, p) {
if (p == last_found)
continue;
@@ -253,20 +295,6 @@
}
}
- return -1;
-}
-
-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;
-
- if (backend->last_found &&
- git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == 0)
- return 0;
-
- if (!pack_entry_find_inner(e, backend, oid, last_found))
- return 0;
-
return git_odb__error_notfound(
"failed to find pack entry", oid, GIT_OID_HEXSZ);
}
@@ -281,22 +309,35 @@
size_t i;
git_oid found_full_oid = {{0}};
bool found = false;
- struct git_pack_file *last_found = backend->last_found;
+ struct git_pack_file *last_found = backend->last_found, *p;
+ git_midx_entry midx_entry;
+
+ 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->sha1, &midx_entry.sha1);
+ e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
+ git_oid_cpy(&found_full_oid, &e->sha1);
+ 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->sha1, &found_full_oid))
+ return git_odb__error_ambiguous("found multiple pack entries");
git_oid_cpy(&found_full_oid, &e->sha1);
found = true;
}
}
- for (i = 0; i < backend->packs.length; ++i) {
- struct git_pack_file *p;
-
- p = git_vector_get(&backend->packs, i);
+ git_vector_foreach(&backend->packs, i, p) {
if (p == last_found)
continue;
@@ -319,6 +360,141 @@
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;
+ size_t cmp_len = strlen(packfile_name);
+ struct git_pack_file *pack;
+ size_t found_position;
+ git_buf pack_path = GIT_BUF_INIT, index_prefix = GIT_BUF_INIT;
+
+ error = git_buf_joinpath(&pack_path, backend->pack_folder, packfile_name);
+ if (error < 0)
+ return error;
+
+ /* This is ensured by midx__parse_packfile_name() */
+ if (cmp_len <= strlen(".idx") || git__suffixcmp(git_buf_cstr(&pack_path), ".idx") != 0)
+ return git_odb__error_notfound("midx file contained a non-index", NULL, 0);
+
+ cmp_len -= strlen(".idx");
+ git_buf_attach_notowned(&index_prefix, git_buf_cstr(&pack_path), cmp_len);
+
+ 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_buf_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_buf_cstr(&pack_path));
+ git_buf_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_buf midx_path = GIT_BUF_INIT;
+ const char *packfile_name;
+ size_t i;
+
+ error = git_buf_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_buf_cstr(&midx_path))) {
+ git_buf_dispose(&midx_path);
+ return 0;
+ }
+ error = remove_multi_pack_index(backend);
+ if (error < 0) {
+ git_buf_dispose(&midx_path);
+ return error;
+ }
+ }
+
+ error = git_midx_open(&backend->midx, git_buf_cstr(&midx_path));
+ git_buf_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;
+}
/***********************************************************
*
@@ -340,9 +516,16 @@
if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
return git_odb__error_notfound("failed to refresh packfiles", NULL, 0);
- git_buf_sets(&path, backend->pack_folder);
+ 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_buf_sets(&path, backend->pack_folder);
error = git_path_direach(&path, 0, packfile_load__cb, backend);
git_buf_dispose(&path);
@@ -358,7 +541,10 @@
struct git_pack_entry e;
int error;
- assert(len_p && type_p && backend && oid);
+ 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;
@@ -469,13 +655,17 @@
struct pack_backend *backend;
unsigned int i;
- assert(_backend && cb);
+ 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)
+ 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;
@@ -488,7 +678,7 @@
{
struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
- assert(writepack);
+ GIT_ASSERT_ARG(writepack);
return git_indexer_append(writepack->indexer, data, size, stats);
}
@@ -497,16 +687,19 @@
{
struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
- assert(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 = (struct pack_writepack *)_writepack;
+ struct pack_writepack *writepack;
- assert(writepack);
+ if (!_writepack)
+ return;
+
+ writepack = (struct pack_writepack *)_writepack;
git_indexer_free(writepack->indexer);
git__free(writepack);
@@ -522,7 +715,8 @@
struct pack_backend *backend;
struct pack_writepack *writepack;
- assert(out && _backend);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(_backend);
*out = NULL;
@@ -553,17 +747,21 @@
static void pack_backend__free(git_odb_backend *_backend)
{
struct pack_backend *backend;
+ struct git_pack_file *p;
size_t i;
- assert(_backend);
+ if (!_backend)
+ return;
backend = (struct pack_backend *)_backend;
- for (i = 0; i < backend->packs.length; ++i) {
- struct git_pack_file *p = git_vector_get(&backend->packs, i);
+ 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_free(&backend->midx_packs);
git_vector_free(&backend->packs);
git__free(backend->pack_folder);
git__free(backend);
@@ -574,7 +772,12 @@
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_free(&backend->midx_packs);
git__free(backend);
return -1;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/oid.c cargo-0.51.0/debian/libgit2/src/oid.c
--- cargo-0.47.0/debian/libgit2/src/oid.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/oid.c 2021-04-07 03:36:48.000000000 +0000
@@ -9,7 +9,7 @@
#include "git2/oid.h"
#include "repository.h"
-#include "global.h"
+#include "threadstate.h"
#include
#include
@@ -26,7 +26,8 @@
size_t p;
int v;
- assert(out && str);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(str);
if (!length)
return oid_error_invalid("too short");
@@ -107,7 +108,7 @@
char *git_oid_tostr_s(const git_oid *oid)
{
- char *str = GIT_GLOBAL->oid_fmt;
+ char *str = GIT_THREADSTATE->oid_fmt;
git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
return str;
}
@@ -253,10 +254,12 @@
return 1;
}
+#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;
@@ -314,7 +317,7 @@
{
git_oid_shorten *os;
- assert((size_t)((int)min_length) == min_length);
+ GIT_ASSERT_ARG_WITH_RETVAL((size_t)((int)min_length) == min_length, NULL);
os = git__calloc(1, sizeof(git_oid_shorten));
if (os == NULL)
diff -Nru cargo-0.47.0/debian/libgit2/src/pack.c cargo-0.51.0/debian/libgit2/src/pack.c
--- cargo-0.47.0/debian/libgit2/src/pack.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pack.c 2021-04-07 03:36:48.000000000 +0000
@@ -12,12 +12,13 @@
#include "mwindow.h"
#include "odb.h"
#include "oid.h"
+#include "oidarray.h"
/* Option to bypass checking existence of '.keep' files */
bool git_disable_pack_keep_file_checks = false;
-static int packfile_open(struct git_pack_file *p);
-static off64_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
+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,
@@ -56,7 +57,7 @@
if (!e)
return NULL;
- git_atomic_inc(&e->refcount);
+ git_atomic32_inc(&e->refcount);
memcpy(&e->raw, source, sizeof(git_rawobj));
return e;
@@ -67,7 +68,6 @@
git_pack_cache_entry *e = (git_pack_cache_entry *)o;
if (e != NULL) {
- assert(e->refcount.val == 0);
git__free(e->raw.data);
git__free(e);
}
@@ -114,7 +114,7 @@
return NULL;
if ((entry = git_offmap_get(cache->entries, offset)) != NULL) {
- git_atomic_inc(&entry->refcount);
+ git_atomic32_inc(&entry->refcount);
entry->last_usage = cache->use_ctr++;
}
git_mutex_unlock(&cache->lock);
@@ -129,7 +129,7 @@
git_pack_cache_entry *entry;
git_offmap_foreach(cache->entries, offset, entry, {
- if (entry && entry->refcount.val == 0) {
+ if (entry && git_atomic32_get(&entry->refcount) == 0) {
cache->memory_used -= entry->raw.len;
git_offmap_delete(cache->entries, offset);
free_cache_object(entry);
@@ -196,7 +196,8 @@
}
}
-static int pack_index_check(const char *path, struct git_pack_file *p)
+/* 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, i, *index;
@@ -302,40 +303,36 @@
return 0;
}
-static int pack_index_open(struct git_pack_file *p)
+/* 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_buf idx_name;
+ git_buf idx_name = GIT_BUF_INIT;
if (p->index_version > -1)
- return 0;
+ goto cleanup;
+ /* checked by git_pack_file alloc */
name_len = strlen(p->pack_name);
- assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
+ GIT_ASSERT(name_len > strlen(".pack"));
- if (git_buf_init(&idx_name, name_len) < 0)
- return -1;
+ if ((error = git_buf_init(&idx_name, name_len)) < 0)
+ goto cleanup;
git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
git_buf_puts(&idx_name, ".idx");
if (git_buf_oom(&idx_name)) {
- git_buf_dispose(&idx_name);
- return -1;
- }
-
- if ((error = git_mutex_lock(&p->lock)) < 0) {
- git_buf_dispose(&idx_name);
- return error;
+ error = -1;
+ goto cleanup;
}
if (p->index_version == -1)
- error = pack_index_check(idx_name.ptr, p);
+ error = pack_index_check_locked(idx_name.ptr, p);
+cleanup:
git_buf_dispose(&idx_name);
- git_mutex_unlock(&p->lock);
-
return error;
}
@@ -345,8 +342,20 @@
off64_t offset,
unsigned int *left)
{
- if (p->mwf.fd == -1 && packfile_open(p) < 0)
+ 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
@@ -357,11 +366,16 @@
* around.
*/
if (offset > (p->mwf.size - 20))
- return NULL;
+ goto cleanup;
if (offset < 0)
- return NULL;
+ goto cleanup;
+
+ pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, 20, left);
- return git_mwindow_open(&p->mwf, w_cursor, offset, 20, left);
+cleanup:
+ git_mutex_unlock(&p->mwf.lock);
+ git_mutex_unlock(&p->lock);
+ return pack_data;
}
/*
@@ -372,12 +386,12 @@
* - each byte afterwards: low seven bits are size continuation,
* with the high bit being "size continues"
*/
-size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type)
+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;
- assert(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
+ GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
/* TODO: add support for chunked objects; see git.git 6c0d19b1 */
@@ -392,7 +406,8 @@
}
*hdr++ = c;
- return (hdr - hdr_base);
+ *out = (hdr - hdr_base);
+ return 0;
}
@@ -436,14 +451,27 @@
int git_packfile_unpack_header(
size_t *size_p,
git_object_t *type_p,
- git_mwindow_file *mwf,
+ struct git_pack_file *p,
git_mwindow **w_curs,
off64_t *curpos)
{
unsigned char *base;
unsigned int left;
unsigned long used;
- int ret;
+ 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 + 20) available
* as a range that we can look at at. (Its actually the hash
@@ -451,16 +479,17 @@
* the maximum deflated object size is 2^137, which is just
* insane, so we know won't exceed what we have been given.
*/
-/* base = pack_window_open(p, w_curs, *curpos, &left); */
- base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left);
+ base = git_mwindow_open(&p->mwf, w_curs, *curpos, 20, &left);
+ git_mutex_unlock(&p->lock);
+ git_mutex_unlock(&p->mwf.lock);
if (base == NULL)
return GIT_EBUFS;
- ret = packfile_unpack_header1(&used, size_p, type_p, base, left);
+ error = packfile_unpack_header1(&used, size_p, type_p, base, left);
git_mwindow_close(w_curs);
- if (ret == GIT_EBUFS)
- return ret;
- else if (ret < 0)
+ if (error == GIT_EBUFS)
+ return error;
+ else if (error < 0)
return packfile_error("header length is zero");
*curpos += used;
@@ -480,7 +509,27 @@
off64_t base_offset;
int error;
- error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos);
+ 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;
@@ -488,8 +537,12 @@
size_t base_size;
git_packfile_stream stream;
- base_offset = get_delta_base(p, &w_curs, &curpos, type, offset);
+ 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);
@@ -503,13 +556,17 @@
while (type == GIT_OBJECT_OFS_DELTA || type == GIT_OBJECT_REF_DELTA) {
curpos = base_offset;
- error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos);
+ 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;
- base_offset = get_delta_base(p, &w_curs, &curpos, type, base_offset);
+
+ 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;
@@ -570,8 +627,7 @@
elem->base_key = obj_offset;
- error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos);
-
+ error = git_packfile_unpack_header(&size, &type, p, &w_curs, &curpos);
if (error < 0)
goto on_error;
@@ -583,17 +639,11 @@
if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
break;
- base_offset = get_delta_base(p, &w_curs, &curpos, type, obj_offset);
+ error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, obj_offset);
git_mwindow_close(&w_curs);
- if (base_offset == 0) {
- error = packfile_error("delta offset is zero");
- goto on_error;
- }
- if (base_offset < 0) { /* must actually be an error code */
- error = (int)base_offset;
+ if (error < 0)
goto on_error;
- }
/* we need to pass the pos *after* the delta-base bit */
elem->offset = curpos;
@@ -628,6 +678,25 @@
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
*/
@@ -690,7 +759,7 @@
GIT_ERROR_CHECK_ALLOC(obj->data);
memcpy(obj->data, data, obj->len + 1);
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
goto cleanup;
}
@@ -738,7 +807,7 @@
}
if (cached) {
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
cached = NULL;
}
@@ -752,7 +821,7 @@
if (error < 0) {
git__free(obj->data);
if (cached)
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
}
if (elem)
@@ -839,10 +908,13 @@
do {
size_t bytes = buffer_len - total;
- unsigned int window_len;
+ unsigned int window_len, consumed;
unsigned char *in;
- in = pack_window_open(p, mwindow, *position, &window_len);
+ 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) {
@@ -852,9 +924,17 @@
git_mwindow_close(mwindow);
- *position += window_len - zstream.in_len;
+ 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 (total < size);
+ } while (!git_zstream_eos(&zstream));
if (total != size || !git_zstream_eos(&zstream)) {
git_error_set(GIT_ERROR_ZLIB, "error inflating zlib stream");
@@ -878,18 +958,21 @@
* curpos is where the data starts, delta_obj_offset is the where the
* header starts
*/
-off64_t get_delta_base(
- struct git_pack_file *p,
- git_mwindow **w_curs,
- off64_t *curpos,
- git_object_t type,
- off64_t delta_obj_offset)
+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)
@@ -909,12 +992,12 @@
return GIT_EBUFS;
unsigned_base_offset += 1;
if (!unsigned_base_offset || MSB(unsigned_base_offset, 7))
- return 0; /* overflow */
+ 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 0; /* out of bound */
+ return packfile_error("out of bounds");
base_offset = delta_obj_offset - unsigned_base_offset;
*curpos += used;
} else if (type == GIT_OBJECT_REF_DELTA) {
@@ -925,8 +1008,12 @@
git_oid_fromraw(&oid, base_info);
if ((entry = git_oidmap_get(p->idx_cache, &oid)) != NULL) {
+ if (entry->offset == 0)
+ return packfile_error("delta offset is zero");
+
*curpos += 20;
- return entry->offset;
+ *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
@@ -941,9 +1028,13 @@
return packfile_error("base entry delta is not in the same pack");
*curpos += 20;
} else
- return 0;
+ return packfile_error("unknown object type");
+
+ if (base_offset == 0)
+ return packfile_error("delta offset is zero");
- return base_offset;
+ *delta_base_out = base_offset;
+ return 0;
}
/***********************************************************
@@ -952,63 +1043,63 @@
*
***********************************************************/
-void git_packfile_close(struct git_pack_file *p, bool unlink_packfile)
+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_locked(&p->mwf);
+ 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);
-}
-
-void git_packfile_free(struct git_pack_file *p)
-{
- if (!p)
- return;
-
- cache_free(&p->bases);
-
- git_packfile_close(p, false);
pack_index_free(p);
git__free(p->bad_object_sha1);
- git_mutex_free(&p->lock);
git_mutex_free(&p->bases.lock);
+ git_mutex_free(&p->mwf.lock);
+ git_mutex_free(&p->lock);
git__free(p);
}
-static int packfile_open(struct git_pack_file *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;
git_oid sha1;
unsigned char *idx_sha1;
- if (p->index_version == -1 && pack_index_open(p) < 0)
+ if (pack_index_open_locked(p) < 0)
return git_odb__error_notfound("failed to open packfile", NULL, 0);
- /* if mwf opened by another thread, return now */
- if (git_mutex_lock(&p->lock) < 0)
- return packfile_error("failed to get lock for open");
-
- if (p->mwf.fd >= 0) {
- git_mutex_unlock(&p->lock);
+ 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_mwindow_file_register(&p->mwf) < 0)
+ 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) {
@@ -1048,7 +1139,9 @@
if (git_oid__cmp(&sha1, (git_oid *)idx_sha1) != 0)
goto cleanup;
- git_mutex_unlock(&p->lock);
+ if (git_mwindow_file_register(&p->mwf) < 0)
+ goto cleanup;
+
return 0;
cleanup:
@@ -1058,8 +1151,6 @@
p_close(p->mwf.fd);
p->mwf.fd = -1;
- git_mutex_unlock(&p->lock);
-
return -1;
}
@@ -1129,13 +1220,22 @@
p->mtime = (git_time_t)st.st_mtime;
p->index_version = -1;
- if (git_mutex_init(&p->lock)) {
+ 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;
}
@@ -1151,28 +1251,29 @@
*
***********************************************************/
-static off64_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
+static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t n)
{
- const unsigned char *index = p->index_map.data;
- const unsigned char *end = index + p->index_map.len;
+ 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) {
+ if (p->index_version == 1)
return ntohl(*((uint32_t *)(index + 24 * n)));
- } else {
- uint32_t off;
- index += 8 + p->num_objects * (20 + 4);
- off = ntohl(*((uint32_t *)(index + 4 * n)));
- if (!(off & 0x80000000))
- return off;
- index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
- /* Make sure we're not being sent out of bounds */
- if (index >= end - 8)
- return -1;
+ index += 8 + p->num_objects * (20 + 4);
+ off32 = ntohl(*((uint32_t *)(index + 4 * n)));
+ if (!(off32 & 0x80000000))
+ return off32;
+ index += p->num_objects * 4 + (off32 & 0x7fffffff) * 8;
- return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
- ntohl(*((uint32_t *)(index + 4)));
- }
+ /* 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) {
@@ -1184,33 +1285,40 @@
git_odb_foreach_cb cb,
void *data)
{
- const unsigned char *index = p->index_map.data, *current;
+ const unsigned char *index, *current;
uint32_t i;
int error = 0;
+ git_array_oid_t oids = GIT_ARRAY_INIT;
+ git_oid *oid;
- if (index == NULL) {
- if ((error = pack_index_open(p)) < 0)
- return error;
-
- assert(p->index_map.data);
+ if (git_mutex_lock(&p->lock) < 0)
+ return packfile_error("failed to get lock for git_pack_foreach_entry");
- index = p->index_map.data;
+ if ((error = pack_index_open_locked(p)) < 0) {
+ git_mutex_unlock(&p->lock);
+ return error;
}
- if (p->index_version > 1) {
+ GIT_ASSERT(p->index_map.data);
+ index = p->index_map.data;
+
+ if (p->index_version > 1)
index += 8;
- }
index += 4 * 256;
if (p->oids == NULL) {
git_vector offsets, oids;
- if ((error = git_vector_init(&oids, p->num_objects, NULL)))
+ 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)))
+ 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 + 24 * p->num_objects;
@@ -1231,21 +1339,44 @@
p->oids = (git_oid **)git_vector_detach(NULL, NULL, &oids);
}
- for (i = 0; i < p->num_objects; i++)
- if ((error = cb(p->oids[i], data)) != 0)
- return git_error_set_after_callback(error);
+ /* We need to copy the OIDs to another array before we relinquish the lock to avoid races. */
+ 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_cpy(oid, p->oids[i]);
+ }
+
+ 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;
}
-static int sha1_position(const void *table, size_t stride, unsigned lo,
- unsigned hi, const unsigned char *key)
+int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
+ unsigned hi, const unsigned char *oid_prefix)
{
- const unsigned char *base = table;
+ const unsigned char *base = oid_lookup_table;
while (lo < hi) {
unsigned mi = (lo + hi) / 2;
- int cmp = git_oid__hashcmp(base + mi * stride, key);
+ int cmp = git_oid__hashcmp(base + mi * stride, oid_prefix);
if (!cmp)
return mi;
@@ -1272,17 +1403,17 @@
int pos, found = 0;
off64_t offset;
const unsigned char *current = 0;
+ int error = 0;
*offset_out = 0;
- if (p->index_version == -1) {
- int error;
+ if (git_mutex_lock(&p->lock) < 0)
+ return packfile_error("failed to get lock for pack_entry_find_offset");
- if ((error = pack_index_open(p)) < 0)
- return error;
- assert(p->index_map.data);
- }
+ if ((error = pack_index_open_locked(p)) < 0)
+ goto cleanup;
+ GIT_ASSERT(p->index_map.data);
index = p->index_map.data;
level1_ofs = p->index_map.data;
@@ -1307,7 +1438,7 @@
short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects);
#endif
- pos = sha1_position(index, stride, lo, hi, short_oid->id);
+ pos = git_pack__lookup_sha1(index, stride, lo, hi, short_oid->id);
if (pos >= 0) {
/* An object matching exactly the oid was found */
@@ -1334,14 +1465,19 @@
}
}
- if (!found)
- return git_odb__error_notfound("failed to find offset for pack entry", short_oid, len);
- if (found > 1)
- return git_odb__error_ambiguous("found multiple offsets for pack entry");
+ 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(p, pos)) < 0) {
+ if ((offset = nth_packed_object_offset_locked(p, pos)) < 0) {
git_error_set(GIT_ERROR_ODB, "packfile index is corrupt");
- return -1;
+ error = -1;
+ goto cleanup;
}
*offset_out = offset;
@@ -1356,7 +1492,9 @@
}
#endif
- return 0;
+cleanup:
+ git_mutex_unlock(&p->lock);
+ return error;
}
int git_pack_entry_find(
@@ -1369,7 +1507,7 @@
git_oid found_oid;
int error;
- assert(p);
+ GIT_ASSERT_ARG(p);
if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
unsigned i;
@@ -1382,10 +1520,26 @@
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(p)) < 0)
+ 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;
diff -Nru cargo-0.47.0/debian/libgit2/src/pack.h cargo-0.51.0/debian/libgit2/src/pack.h
--- cargo-0.47.0/debian/libgit2/src/pack.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pack.h 2021-04-07 03:36:48.000000000 +0000
@@ -58,7 +58,7 @@
typedef struct git_pack_cache_entry {
size_t last_usage; /* enough? */
- git_atomic refcount;
+ git_atomic32 refcount;
git_rawobj raw;
} git_pack_cache_entry;
@@ -85,8 +85,8 @@
struct git_pack_file {
git_mwindow_file mwf;
git_map index_map;
- git_mutex lock; /* protect updates to mwf and index_map */
- git_atomic refcount;
+ git_mutex lock; /* protect updates to index_map */
+ git_atomic32 refcount;
uint32_t num_objects;
uint32_t num_bad_objects;
@@ -106,6 +106,19 @@
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 = 24), whereas files with version 2 store them in a contiguous
+ * flat array (stride = 20).
+ */
+int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo,
+ unsigned hi, const unsigned char *oid_prefix);
+
struct git_pack_entry {
off64_t offset;
git_oid sha1;
@@ -120,14 +133,14 @@
git_mwindow *mw;
} git_packfile_stream;
-size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type);
+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,
- git_mwindow_file *mwf,
+ struct git_pack_file *p,
git_mwindow **w_curs,
off64_t *curpos);
@@ -143,12 +156,15 @@
ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
void git_packfile_stream_dispose(git_packfile_stream *obj);
-off64_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
- off64_t *curpos, git_object_t type,
+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_close(struct git_pack_file *p, bool unlink_packfile);
-void git_packfile_free(struct git_pack_file *p);
+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);
int git_pack_entry_find(
diff -Nru cargo-0.47.0/debian/libgit2/src/pack-objects.c cargo-0.51.0/debian/libgit2/src/pack-objects.c
--- cargo-0.47.0/debian/libgit2/src/pack-objects.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pack-objects.c 2021-04-07 03:36:48.000000000 +0000
@@ -12,7 +12,7 @@
#include "iterator.h"
#include "netops.h"
#include "pack.h"
-#include "thread-utils.h"
+#include "thread.h"
#include "tree.h"
#include "util.h"
#include "revwalk.h"
@@ -48,18 +48,10 @@
};
#ifdef GIT_THREADS
-
-#define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) do { \
- int result = git_mutex_##op(&(pb)->mtx); \
- assert(!result); \
- GIT_UNUSED(result); \
- } while (0)
-
+# define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) git_mutex_##op(&(pb)->mtx)
#else
-
-#define GIT_PACKBUILDER__MUTEX_OP(pb,mtx,op) GIT_UNUSED(pb)
-
-#endif /* GIT_THREADS */
+# 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)
@@ -141,14 +133,11 @@
pb = git__calloc(1, sizeof(*pb));
GIT_ERROR_CHECK_ALLOC(pb);
- if (git_oidmap_new(&pb->object_ix) < 0)
- goto on_error;
-
- if (git_oidmap_new(&pb->walk_objects) < 0)
+ if (git_oidmap_new(&pb->object_ix) < 0 ||
+ git_oidmap_new(&pb->walk_objects) < 0 ||
+ git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0)
goto on_error;
- git_pool_init(&pb->object_pool, sizeof(struct walk_object));
-
pb->repo = repo;
pb->nr_threads = 1; /* do not spawn any thread by default */
@@ -180,13 +169,13 @@
unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
{
- assert(pb);
+ GIT_ASSERT_ARG(pb);
#ifdef GIT_THREADS
pb->nr_threads = n;
#else
GIT_UNUSED(n);
- assert(1 == pb->nr_threads);
+ GIT_ASSERT(pb->nr_threads == 1);
#endif
return pb->nr_threads;
@@ -214,7 +203,8 @@
size_t newsize;
int ret;
- assert(pb && oid);
+ 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 */
@@ -350,10 +340,9 @@
}
/* Write header */
- hdr_len = git_packfile__object_header(hdr, data_len, type);
-
- if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
- (error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
+ 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) {
@@ -855,10 +844,11 @@
}
}
- git_packbuilder__cache_lock(pb);
+ GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
+
if (trg_object->delta_data) {
git__free(trg_object->delta_data);
- assert(pb->delta_cache_size >= trg_object->delta_size);
+ GIT_ASSERT(pb->delta_cache_size >= trg_object->delta_size);
pb->delta_cache_size -= trg_object->delta_size;
trg_object->delta_data = NULL;
}
@@ -866,7 +856,7 @@
bool overflow = git__add_sizet_overflow(
&pb->delta_cache_size, pb->delta_cache_size, delta_size);
- git_packbuilder__cache_unlock(pb);
+ GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
if (overflow) {
git__free(delta_buf);
@@ -877,7 +867,7 @@
GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
} else {
/* create delta when writing the pack */
- git_packbuilder__cache_unlock(pb);
+ GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
git__free(delta_buf);
}
@@ -965,9 +955,9 @@
struct unpacked *n = array + idx;
size_t max_depth, j, best_base = SIZE_MAX;
- git_packbuilder__progress_lock(pb);
+ GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
if (!*list_size) {
- git_packbuilder__progress_unlock(pb);
+ GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
break;
}
@@ -976,7 +966,7 @@
po = *list++;
(*list_size)--;
- git_packbuilder__progress_unlock(pb);
+ GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
mem_usage -= free_unpacked(n);
n->object = po;
@@ -1051,10 +1041,10 @@
po->z_delta_size = zbuf.size;
git_buf_clear(&zbuf);
- git_packbuilder__cache_lock(pb);
+ GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
pb->delta_cache_size -= po->delta_size;
pb->delta_cache_size += po->z_delta_size;
- git_packbuilder__cache_unlock(pb);
+ GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
}
/*
@@ -1132,10 +1122,10 @@
; /* TODO */
}
- git_packbuilder__progress_lock(me->pb);
+ GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_lock(me->pb) == 0, NULL);
me->working = 0;
git_cond_signal(&me->pb->progress_cond);
- git_packbuilder__progress_unlock(me->pb);
+ 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");
@@ -1168,7 +1158,7 @@
int ret, active_threads = 0;
if (!pb->nr_threads)
- pb->nr_threads = git_online_cpus();
+ pb->nr_threads = git__online_cpus();
if (pb->nr_threads <= 1) {
find_deltas(pb, list, &list_size, window, depth);
@@ -1240,7 +1230,7 @@
* 'working' flag from 1 -> 0. This indicates that it is
* ready to receive more work using our work-stealing
* algorithm. */
- git_packbuilder__progress_lock(pb);
+ GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
for (;;) {
for (i = 0; !target && i < pb->nr_threads; i++)
if (!p[i].working)
@@ -1283,7 +1273,7 @@
target->list_size = sub_size;
target->remaining = sub_size;
target->working = 1;
- git_packbuilder__progress_unlock(pb);
+ 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");
@@ -1366,8 +1356,13 @@
int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
{
+ int error;
+
+ if ((error = git_buf_sanitize(buf)) < 0)
+ return error;
+
PREPARE_PACK;
- git_buf_sanitize(buf);
+
return write_pack(pb, &write_pack_buf, buf);
}
@@ -1384,20 +1379,29 @@
git_indexer_progress_cb progress_cb,
void *progress_cb_payload)
{
+ int error = -1;
+ git_buf object_path = GIT_BUF_INIT;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
- git_indexer *indexer;
+ git_indexer *indexer = NULL;
git_indexer_progress stats;
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_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
+ goto cleanup;
+ path = git_buf_cstr(&object_path);
+ }
+
opts.progress_cb = progress_cb;
opts.progress_cb_payload = progress_cb_payload;
- if (git_indexer_new(
- &indexer, path, mode, pb->odb, &opts) < 0)
- return -1;
+ if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
+ goto cleanup;
if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
git_indexer__set_fsync(indexer, 1);
@@ -1405,16 +1409,18 @@
ctx.indexer = indexer;
ctx.stats = &stats;
- if (git_packbuilder_foreach(pb, write_cb, &ctx) < 0 ||
- git_indexer_commit(indexer, &stats) < 0) {
- git_indexer_free(indexer);
- return -1;
- }
+ if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0)
+ goto cleanup;
+
+ if ((error = git_indexer_commit(indexer, &stats)) < 0)
+ goto cleanup;
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
+cleanup:
git_indexer_free(indexer);
- return 0;
+ git_buf_dispose(&object_path);
+ return error;
}
#undef PREPARE_PACK
@@ -1478,7 +1484,8 @@
git_object *obj;
int error;
- assert(pb && id);
+ GIT_ASSERT_ARG(pb);
+ GIT_ASSERT_ARG(id);
if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
return error;
@@ -1634,7 +1641,7 @@
return 0;
}
-int insert_tree(git_packbuilder *pb, git_tree *tree)
+static int pack_objects_insert_tree(git_packbuilder *pb, git_tree *tree)
{
size_t i;
int error;
@@ -1661,7 +1668,7 @@
if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0)
return error;
- error = insert_tree(pb, subtree);
+ error = pack_objects_insert_tree(pb, subtree);
git_tree_free(subtree);
if (error < 0)
@@ -1687,7 +1694,7 @@
return error;
}
-int insert_commit(git_packbuilder *pb, struct walk_object *obj)
+static int pack_objects_insert_commit(git_packbuilder *pb, struct walk_object *obj)
{
int error;
git_commit *commit = NULL;
@@ -1704,7 +1711,7 @@
if ((error = git_tree_lookup(&tree, pb->repo, git_commit_tree_id(commit))) < 0)
goto cleanup;
- if ((error = insert_tree(pb, tree)) < 0)
+ if ((error = pack_objects_insert_tree(pb, tree)) < 0)
goto cleanup;
cleanup:
@@ -1719,7 +1726,8 @@
git_oid id;
struct walk_object *obj;
- assert(pb && walk);
+ GIT_ASSERT_ARG(pb);
+ GIT_ASSERT_ARG(walk);
if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
return error;
@@ -1739,7 +1747,7 @@
if (obj->seen || obj->uninteresting)
continue;
- if ((error = insert_commit(pb, obj)) < 0)
+ if ((error = pack_objects_insert_commit(pb, obj)) < 0)
return error;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/patch.c cargo-0.51.0/debian/libgit2/src/patch.c
--- cargo-0.47.0/debian/libgit2/src/patch.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/patch.c 2021-04-07 03:36:48.000000000 +0000
@@ -65,7 +65,7 @@
{
size_t out;
- assert(patch);
+ GIT_ASSERT_ARG(patch);
out = patch->content_size;
@@ -129,13 +129,13 @@
const git_diff_delta *git_patch_get_delta(const git_patch *patch)
{
- assert(patch);
+ GIT_ASSERT_ARG_WITH_RETVAL(patch, NULL);
return patch->delta;
}
size_t git_patch_num_hunks(const git_patch *patch)
{
- assert(patch);
+ GIT_ASSERT_ARG(patch);
return git_array_size(patch->hunks);
}
@@ -152,7 +152,7 @@
size_t hunk_idx)
{
git_patch_hunk *hunk;
- assert(patch);
+ GIT_ASSERT_ARG(patch);
hunk = git_array_get(patch->hunks, hunk_idx);
@@ -170,7 +170,7 @@
int git_patch_num_lines_in_hunk(const git_patch *patch, size_t hunk_idx)
{
git_patch_hunk *hunk;
- assert(patch);
+ GIT_ASSERT_ARG(patch);
if (!(hunk = git_array_get(patch->hunks, hunk_idx)))
return patch_error_outofrange("hunk");
@@ -186,7 +186,7 @@
git_patch_hunk *hunk;
git_diff_line *line;
- assert(patch);
+ GIT_ASSERT_ARG(patch);
if (!(hunk = git_array_get(patch->hunks, hunk_idx))) {
if (out) *out = NULL;
@@ -206,7 +206,9 @@
int git_patch_from_diff(git_patch **out, git_diff *diff, size_t idx)
{
- assert(out && diff && diff->patch_fn);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
+ GIT_ASSERT_ARG(diff->patch_fn);
return diff->patch_fn(out, diff, idx);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/patch_generate.c cargo-0.51.0/debian/libgit2/src/patch_generate.c
--- cargo-0.47.0/debian/libgit2/src/patch_generate.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/patch_generate.c 2021-04-07 03:36:48.000000000 +0000
@@ -209,9 +209,7 @@
if ((error = git_diff_file_content__load(
&patch->ofile, &patch->base.diff_opts)) < 0 ||
- should_skip_binary(patch, patch->ofile.file))
- goto cleanup;
- if ((error = git_diff_file_content__load(
+ (error = git_diff_file_content__load(
&patch->nfile, &patch->base.diff_opts)) < 0 ||
should_skip_binary(patch, patch->nfile.file))
goto cleanup;
@@ -563,7 +561,7 @@
patch_generated_with_delta *pd;
git_xdiff_output xo;
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
if ((error = patch_generated_with_delta_alloc(
@@ -842,7 +840,7 @@
GIT_UNUSED(hunk_);
hunk = git_array_last(patch->base.hunks);
- assert(hunk); /* programmer error if no hunk is available */
+ GIT_ASSERT(hunk); /* programmer error if no hunk is available */
line = git_array_alloc(patch->base.lines);
GIT_ERROR_CHECK_ALLOC(line);
diff -Nru cargo-0.47.0/debian/libgit2/src/patch_parse.c cargo-0.51.0/debian/libgit2/src/patch_parse.c
--- cargo-0.47.0/debian/libgit2/src/patch_parse.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/patch_parse.c 2021-04-07 03:36:48.000000000 +0000
@@ -198,7 +198,7 @@
return -1;
if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ' ') {
- uint16_t mode;
+ uint16_t mode = 0;
git_parse_advance_chars(&ctx->parse_ctx, 1);
@@ -407,10 +407,12 @@
{ "--- " , 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 },
@@ -940,7 +942,7 @@
return parse_patch_hunks(patch, ctx);
}
-int check_header_names(
+static int check_header_names(
const char *one,
const char *two,
const char *old_or_new,
@@ -1166,7 +1168,8 @@
size_t start, used;
int error = 0;
- assert(out && ctx);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ctx);
*out = NULL;
diff -Nru cargo-0.47.0/debian/libgit2/src/path.c cargo-0.51.0/debian/libgit2/src/path.c
--- cargo-0.47.0/debian/libgit2/src/path.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/path.c 2021-04-07 03:36:48.000000000 +0000
@@ -274,24 +274,6 @@
return 0;
}
-const char *git_path_topdir(const char *path)
-{
- size_t len;
- ssize_t i;
-
- assert(path);
- len = strlen(path);
-
- if (!len || path[len - 1] != '/')
- return NULL;
-
- for (i = (ssize_t)len - 2; i >= 0; --i)
- if (path[i] == '/')
- break;
-
- return &path[i + 1];
-}
-
int git_path_root(const char *path)
{
int offset = 0, prefix_len;
@@ -322,10 +304,12 @@
return -1; /* Not a real error - signals that path is not rooted */
}
-void git_path_trim_slashes(git_buf *path)
+static void path_trim_slashes(git_buf *path)
{
int ceiling = git_path_root(path->ptr) + 1;
- assert(ceiling >= 0);
+
+ if (ceiling < 0)
+ return;
while (path->size > (size_t)ceiling) {
if (path->ptr[path->size-1] != '/')
@@ -341,7 +325,8 @@
{
ssize_t root;
- assert(path && path_out);
+ GIT_ASSERT_ARG(path_out);
+ GIT_ASSERT_ARG(path);
root = (ssize_t)git_path_root(path);
@@ -389,7 +374,8 @@
{
char buf[GIT_PATH_MAX];
- assert(path && path_out);
+ GIT_ASSERT_ARG(path_out);
+ GIT_ASSERT_ARG(path);
/* construct path if needed */
if (base != NULL && git_path_root(path) < 0) {
@@ -440,7 +426,9 @@
int git__percent_decode(git_buf *decoded_out, const char *input)
{
int len, hi, lo, i;
- assert(decoded_out && input);
+
+ GIT_ASSERT_ARG(decoded_out);
+ GIT_ASSERT_ARG(input);
len = (int)strlen(input);
git_buf_clear(decoded_out);
@@ -501,7 +489,8 @@
{
int offset;
- assert(local_path_out && file_url);
+ 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] == '/')
@@ -526,7 +515,8 @@
ssize_t stop = 0, scan;
char oldc = '\0';
- assert(path && cb);
+ GIT_ASSERT_ARG(path);
+ GIT_ASSERT_ARG(cb);
if (ceiling != NULL) {
if (git__prefixcmp(path->ptr, ceiling) == 0)
@@ -581,7 +571,7 @@
bool git_path_exists(const char *path)
{
- assert(path);
+ GIT_ASSERT_ARG_WITH_RETVAL(path, false);
return p_access(path, F_OK) == 0;
}
@@ -598,7 +588,7 @@
{
struct stat st;
- assert(path);
+ GIT_ASSERT_ARG_WITH_RETVAL(path, false);
if (p_stat(path, &st) < 0)
return false;
@@ -609,7 +599,7 @@
{
struct stat st;
- assert(path);
+ GIT_ASSERT_ARG_WITH_RETVAL(path, false);
if (p_lstat(path, &st) < 0)
return false;
@@ -1211,7 +1201,8 @@
if (is_win7_or_later < 0)
is_win7_or_later = git_has_win32_version(6, 1, 0);
- assert(diriter && path);
+ GIT_ASSERT_ARG(diriter);
+ GIT_ASSERT_ARG(path);
memset(diriter, 0, sizeof(git_path_diriter));
diriter->handle = INVALID_HANDLE_VALUE;
@@ -1219,7 +1210,7 @@
if (git_buf_puts(&diriter->path_utf8, path) < 0)
return -1;
- git_path_trim_slashes(&diriter->path_utf8);
+ path_trim_slashes(&diriter->path_utf8);
if (diriter->path_utf8.size == 0) {
git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
@@ -1311,9 +1302,10 @@
size_t *out_len,
git_path_diriter *diriter)
{
- assert(out && out_len && diriter);
-
- assert(diriter->path_utf8.size > diriter->parent_utf8_len);
+ 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;
@@ -1325,7 +1317,9 @@
size_t *out_len,
git_path_diriter *diriter)
{
- assert(out && out_len && 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;
@@ -1334,7 +1328,8 @@
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
{
- assert(out && diriter);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diriter);
return git_win32__file_attribute_to_stat(out,
(WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current,
@@ -1361,14 +1356,15 @@
const char *path,
unsigned int flags)
{
- assert(diriter && path);
+ GIT_ASSERT_ARG(diriter);
+ GIT_ASSERT_ARG(path);
memset(diriter, 0, sizeof(git_path_diriter));
if (git_buf_puts(&diriter->path, path) < 0)
return -1;
- git_path_trim_slashes(&diriter->path);
+ path_trim_slashes(&diriter->path);
if (diriter->path.size == 0) {
git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path);
@@ -1401,7 +1397,7 @@
bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
int error = 0;
- assert(diriter);
+ GIT_ASSERT_ARG(diriter);
errno = 0;
@@ -1444,9 +1440,10 @@
size_t *out_len,
git_path_diriter *diriter)
{
- assert(out && out_len && diriter);
-
- assert(diriter->path.size > diriter->parent_len);
+ 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;
@@ -1458,7 +1455,9 @@
size_t *out_len,
git_path_diriter *diriter)
{
- assert(out && out_len && diriter);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(out_len);
+ GIT_ASSERT_ARG(diriter);
*out = diriter->path.ptr;
*out_len = diriter->path.size;
@@ -1467,7 +1466,8 @@
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
{
- assert(out && diriter);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diriter);
return git_path_lstat(diriter->path.ptr, out);
}
@@ -1503,7 +1503,8 @@
char *dup;
int error;
- assert(contents && path);
+ GIT_ASSERT_ARG(contents);
+ GIT_ASSERT_ARG(path);
if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
return error;
@@ -1512,7 +1513,7 @@
if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
break;
- assert(name_len > prefix_len);
+ GIT_ASSERT(name_len > prefix_len);
dup = git__strndup(name + prefix_len, name_len - prefix_len);
GIT_ERROR_CHECK_ALLOC(dup);
@@ -2045,7 +2046,7 @@
git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is not valid");
ret = GIT_ERROR;
}
- free(info);
+ git__free(info);
cleanup:
if (descriptor)
diff -Nru cargo-0.47.0/debian/libgit2/src/path.h cargo-0.51.0/debian/libgit2/src/path.h
--- cargo-0.47.0/debian/libgit2/src/path.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/path.h 2021-04-07 03:36:48.000000000 +0000
@@ -67,8 +67,6 @@
*/
extern size_t git_path_basename_offset(git_buf *buffer);
-extern const char *git_path_topdir(const char *path);
-
/**
* Find offset to root of path if path has one.
*
diff -Nru cargo-0.47.0/debian/libgit2/src/pathspec.c cargo-0.51.0/debian/libgit2/src/pathspec.c
--- cargo-0.47.0/debian/libgit2/src/pathspec.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pathspec.c 2021-04-07 03:36:48.000000000 +0000
@@ -238,9 +238,9 @@
memset(ps, 0, sizeof(*ps));
ps->prefix = git_pathspec_prefix(paths);
- git_pool_init(&ps->pool, 1);
- if ((error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
+ 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;
@@ -289,7 +289,8 @@
bool no_fnmatch = (flags & GIT_PATHSPEC_NO_GLOB) != 0;
bool casefold = (flags & GIT_PATHSPEC_IGNORE_CASE) != 0;
- assert(ps && path);
+ GIT_ASSERT_ARG(ps);
+ GIT_ASSERT_ARG(path);
return (0 != git_pathspec__match(
&ps->pathspec, path, no_fnmatch, casefold, NULL, NULL));
@@ -316,7 +317,8 @@
if (!m)
return NULL;
- git_pool_init(&m->pool, 1);
+ 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
@@ -525,7 +527,7 @@
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
iter_opts.flags = pathspec_match_iter_flags(flags);
@@ -547,7 +549,7 @@
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
- assert(index);
+ GIT_ASSERT_ARG(index);
iter_opts.flags = pathspec_match_iter_flags(flags);
@@ -569,7 +571,7 @@
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
int error = 0;
- assert(tree);
+ GIT_ASSERT_ARG(tree);
iter_opts.flags = pathspec_match_iter_flags(flags);
@@ -597,7 +599,7 @@
const git_diff_delta *delta, **match;
git_bitvec used_patterns;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
if (git_bitvec_init(&used_patterns, patterns->length) < 0)
return -1;
diff -Nru cargo-0.47.0/debian/libgit2/src/pool.c cargo-0.51.0/debian/libgit2/src/pool.c
--- cargo-0.47.0/debian/libgit2/src/pool.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pool.c 2021-04-07 03:36:48.000000000 +0000
@@ -21,30 +21,29 @@
static void *pool_alloc_page(git_pool *pool, size_t size);
-size_t git_pool__system_page_size(void)
-{
- static size_t size = 0;
+#ifndef GIT_DEBUG_POOL
- if (!size) {
- size_t page_size;
- if (git__page_size(&page_size) < 0)
- page_size = 4096;
- /* allow space for malloc overhead */
- size = (page_size - (2 * sizeof(void *)) - sizeof(git_pool_page));
- }
+static size_t system_page_size = 0;
- return size;
+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;
}
-#ifndef GIT_DEBUG_POOL
-void git_pool_init(git_pool *pool, size_t item_size)
+int git_pool_init(git_pool *pool, size_t item_size)
{
- assert(pool);
- assert(item_size >= 1);
+ 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();
+ pool->page_size = system_page_size;
+
+ return 0;
}
void git_pool_clear(git_pool *pool)
@@ -112,6 +111,11 @@
#else
+int git_pool_global_init(void)
+{
+ return 0;
+}
+
static int git_pool__ptr_cmp(const void * a, const void * b)
{
if(a > b) {
@@ -125,15 +129,17 @@
}
}
-void git_pool_init(git_pool *pool, size_t item_size)
+int git_pool_init(git_pool *pool, size_t item_size)
{
- assert(pool);
- assert(item_size >= 1);
+ 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)
@@ -199,7 +205,9 @@
{
char *ptr = NULL;
- assert(pool && str && pool->item_size == sizeof(char));
+ 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;
@@ -214,7 +222,10 @@
char *git_pool_strdup(git_pool *pool, const char *str)
{
- assert(pool && str && pool->item_size == sizeof(char));
+ 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));
}
@@ -228,7 +239,8 @@
void *ptr;
size_t len_a, len_b, total;
- assert(pool && pool->item_size == sizeof(char));
+ 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;
diff -Nru cargo-0.47.0/debian/libgit2/src/pool.h cargo-0.51.0/debian/libgit2/src/pool.h
--- cargo-0.47.0/debian/libgit2/src/pool.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/pool.h 2021-04-07 03:36:48.000000000 +0000
@@ -81,7 +81,7 @@
* Of course, you can use this in other ways, but those are the
* two most common patterns.
*/
-extern void git_pool_init(git_pool *pool, size_t item_size);
+extern int git_pool_init(git_pool *pool, size_t item_size);
/**
* Free all items in pool
@@ -135,4 +135,12 @@
#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 -Nru cargo-0.47.0/debian/libgit2/src/posix.c cargo-0.51.0/debian/libgit2/src/posix.c
--- cargo-0.47.0/debian/libgit2/src/posix.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/posix.c 2021-04-07 03:36:48.000000000 +0000
@@ -129,7 +129,8 @@
{
char *cwd_buffer;
- assert(buffer_out && size > 0);
+ GIT_ASSERT_ARG(buffer_out);
+ GIT_ASSERT_ARG(size > 0);
cwd_buffer = getcwd(buffer_out, size);
@@ -196,7 +197,7 @@
while (cnt) {
ssize_t r;
#ifdef GIT_WIN32
- assert((size_t)((unsigned int)cnt) == cnt);
+ GIT_ASSERT((size_t)((unsigned int)cnt) == cnt);
r = write(fd, b, (unsigned int)cnt);
#else
r = write(fd, b, cnt);
@@ -263,7 +264,7 @@
int p_munmap(git_map *map)
{
- assert(map != NULL);
+ GIT_ASSERT_ARG(map);
git__free(map->data);
return 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/proxy.c cargo-0.51.0/debian/libgit2/src/proxy.c
--- cargo-0.47.0/debian/libgit2/src/proxy.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/proxy.c 2021-04-07 03:36:48.000000000 +0000
@@ -16,10 +16,12 @@
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)
{
diff -Nru cargo-0.47.0/debian/libgit2/src/push.c cargo-0.51.0/debian/libgit2/src/push.c
--- cargo-0.47.0/debian/libgit2/src/push.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/push.c 2021-04-07 03:36:48.000000000 +0000
@@ -555,7 +555,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/reader.c cargo-0.51.0/debian/libgit2/src/reader.c
--- cargo-0.47.0/debian/libgit2/src/reader.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/reader.c 2021-04-07 03:36:48.000000000 +0000
@@ -61,7 +61,8 @@
{
tree_reader *reader;
- assert(out && tree);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(tree);
reader = git__calloc(1, sizeof(tree_reader));
GIT_ERROR_CHECK_ALLOC(reader);
@@ -158,7 +159,8 @@
workdir_reader *reader;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
reader = git__calloc(1, sizeof(workdir_reader));
GIT_ERROR_CHECK_ALLOC(reader);
@@ -223,7 +225,8 @@
index_reader *reader;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
reader = git__calloc(1, sizeof(index_reader));
GIT_ERROR_CHECK_ALLOC(reader);
@@ -251,7 +254,9 @@
git_reader *reader,
const char *filename)
{
- assert(out && reader && filename);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(reader);
+ GIT_ASSERT_ARG(filename);
return reader->read(out, out_id, out_filemode, reader, filename);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/rebase.c cargo-0.51.0/debian/libgit2/src/rebase.c
--- cargo-0.47.0/debian/libgit2/src/rebase.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/rebase.c 2021-04-07 03:36:48.000000000 +0000
@@ -186,8 +186,8 @@
{
git_rebase_operation *operation;
- assert((type == GIT_REBASE_OPERATION_EXEC) == !id);
- assert((type == GIT_REBASE_OPERATION_EXEC) == !!exec);
+ 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;
@@ -301,7 +301,7 @@
size_t state_path_len;
int error;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if ((error = rebase_check_versions(given_opts)) < 0)
return error;
@@ -501,10 +501,12 @@
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)
{
@@ -699,7 +701,8 @@
bool inmemory = (given_opts && given_opts->inmemory);
int error;
- assert(repo && (upstream || onto));
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(upstream || onto);
*out = NULL;
@@ -910,7 +913,8 @@
{
int error;
- assert(out && rebase);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(rebase);
if ((error = rebase_movenext(rebase)) < 0)
return error;
@@ -929,7 +933,9 @@
git_index **out,
git_rebase *rebase)
{
- assert(out && rebase && rebase->index);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(rebase);
+ GIT_ASSERT_ARG(rebase->index);
GIT_REFCOUNT_INC(rebase->index);
*out = rebase->index;
@@ -1004,12 +1010,12 @@
}
if (git_buf_is_allocated(&commit_signature)) {
- assert(git_buf_contains_nul(&commit_signature));
+ GIT_ASSERT(git_buf_contains_nul(&commit_signature));
commit_signature_string = git_buf_cstr(&commit_signature);
}
if (git_buf_is_allocated(&signature_field)) {
- assert(git_buf_contains_nul(&signature_field));
+ GIT_ASSERT(git_buf_contains_nul(&signature_field));
signature_field_string = git_buf_cstr(&signature_field);
}
@@ -1053,7 +1059,7 @@
int error;
operation = git_array_get(rebase->operations, rebase->current);
- assert(operation);
+ GIT_ASSERT(operation);
if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 ||
(error = git_repository_head(&head, rebase->repo)) < 0 ||
@@ -1093,9 +1099,9 @@
git_commit *commit = NULL;
int error = 0;
- assert(rebase->index);
- assert(rebase->last_commit);
- assert(rebase->current < rebase->operations.size);
+ 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)
@@ -1123,7 +1129,8 @@
{
int error;
- assert(rebase && committer);
+ GIT_ASSERT_ARG(rebase);
+ GIT_ASSERT_ARG(committer);
if (rebase->inmemory)
error = rebase_commit_inmemory(
@@ -1143,7 +1150,7 @@
git_commit *orig_head_commit = NULL;
int error;
- assert(rebase);
+ GIT_ASSERT_ARG(rebase);
if (rebase->inmemory)
return 0;
@@ -1356,7 +1363,7 @@
{
int error = 0;
- assert(rebase);
+ GIT_ASSERT_ARG(rebase);
if (rebase->inmemory)
return 0;
@@ -1371,14 +1378,17 @@
}
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;
}
@@ -1388,21 +1398,21 @@
size_t git_rebase_operation_entrycount(git_rebase *rebase)
{
- assert(rebase);
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, 0);
return git_array_size(rebase->operations);
}
size_t git_rebase_operation_current(git_rebase *rebase)
{
- assert(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)
{
- assert(rebase);
+ GIT_ASSERT_ARG_WITH_RETVAL(rebase, NULL);
return git_array_get(rebase->operations, idx);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/refdb.c cargo-0.51.0/debian/libgit2/src/refdb.c
--- cargo-0.47.0/debian/libgit2/src/refdb.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refdb.c 2021-04-07 03:36:48.000000000 +0000
@@ -17,11 +17,15 @@
#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;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
db = git__calloc(1, sizeof(*db));
GIT_ERROR_CHECK_ALLOC(db);
@@ -38,7 +42,8 @@
git_refdb *db;
git_refdb_backend *dir;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -86,7 +91,7 @@
int git_refdb_compress(git_refdb *db)
{
- assert(db);
+ GIT_ASSERT_ARG(db);
if (db->backend->compress)
return db->backend->compress(db->backend);
@@ -111,7 +116,9 @@
int git_refdb_exists(int *exists, git_refdb *refdb, const char *ref_name)
{
- assert(exists && refdb && refdb->backend);
+ GIT_ASSERT_ARG(exists);
+ GIT_ASSERT_ARG(refdb);
+ GIT_ASSERT_ARG(refdb->backend);
return refdb->backend->exists(exists, refdb->backend, ref_name);
}
@@ -121,7 +128,10 @@
git_reference *ref;
int error;
- assert(db && db->backend && out && ref_name);
+ 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)
@@ -134,6 +144,59 @@
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;
@@ -178,7 +241,8 @@
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)
{
- assert(db && db->backend);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(db->backend);
GIT_REFCOUNT_INC(db);
ref->db = db;
@@ -197,7 +261,9 @@
{
int error;
- assert(db && db->backend);
+ 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;
@@ -212,7 +278,9 @@
int git_refdb_delete(struct git_refdb *db, const char *ref_name, const git_oid *old_id, const char *old_target)
{
- assert(db && db->backend);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(db->backend);
+
return db->backend->del(db->backend, ref_name, old_id, old_target);
}
@@ -220,7 +288,8 @@
{
int error;
- assert(db && db->backend);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(db->backend);
if ((error = db->backend->reflog_read(out, db->backend, name)) < 0)
return error;
@@ -231,16 +300,97 @@
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)
{
- assert(db && 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)
{
- assert(db && refname);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(refname);
return db->backend->ensure_log(db->backend, refname);
}
@@ -254,7 +404,9 @@
int git_refdb_lock(void **payload, git_refdb *db, const char *refname)
{
- assert(payload && db && 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");
@@ -266,7 +418,7 @@
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)
{
- assert(db);
+ GIT_ASSERT_ARG(db);
return db->backend->unlock(db->backend, payload, success, update_reflog, ref, sig, message);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/refdb_fs.c cargo-0.51.0/debian/libgit2/src/refdb_fs.c
--- cargo-0.47.0/debian/libgit2/src/refdb_fs.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refdb_fs.c 2021-04-07 03:36:48.000000000 +0000
@@ -5,8 +5,6 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "refdb_fs.h"
-
#include "refs.h"
#include "hash.h"
#include "repository.h"
@@ -333,7 +331,7 @@
git_buf ref_path = GIT_BUF_INIT;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
*exists = 0;
@@ -474,7 +472,7 @@
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if (!(error = loose_lookup(out, backend, ref_name)))
return 0;
@@ -680,12 +678,13 @@
refdb_fs_iter *iter = NULL;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
iter = git__calloc(1, sizeof(refdb_fs_iter));
GIT_ERROR_CHECK_ALLOC(iter);
- git_pool_init(&iter->pool, 1);
+ if ((error = git_pool_init(&iter->pool, 1)) < 0)
+ goto out;
if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
goto out;
@@ -784,7 +783,9 @@
git_buf ref_path = GIT_BUF_INIT;
const char *basedir;
- assert(file && backend && name);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(name);
if (!git_path_isvalid(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
@@ -820,7 +821,8 @@
static int loose_commit(git_filebuf *file, const git_reference *ref)
{
- assert(file && ref);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(ref);
if (ref->type == GIT_REFERENCE_DIRECT) {
char oid[GIT_OID_HEXSZ + 1];
@@ -830,7 +832,7 @@
} else if (ref->type == GIT_REFERENCE_SYMBOLIC) {
git_filebuf_printf(file, GIT_SYMREF "%s\n", ref->target.symbolic);
} else {
- assert(0); /* don't let this happen */
+ GIT_ASSERT(0);
}
return git_filebuf_commit(file);
@@ -1067,7 +1069,7 @@
for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
struct packref *ref = git_sortedcache_entry(refcache, i);
- assert(ref);
+ GIT_ASSERT(ref);
if ((error = packed_find_peel(backend, ref)) < 0)
goto fail;
@@ -1129,44 +1131,6 @@
}
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 has_reflog(git_repository *repo, const char *name);
-
-static int should_write_reflog(int *write, git_repository *repo, const char *name)
-{
- int error, logall;
-
- error = git_repository__configmap_lookup(&logall, 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(repo);
-
- *write = 0;
- switch (logall) {
- case GIT_LOGALLREFUPDATES_FALSE:
- *write = 0;
- break;
-
- case GIT_LOGALLREFUPDATES_TRUE:
- /* Only write if it already has a log,
- * or if it's under heads/, remotes/ or notes/
- */
- *write = has_reflog(repo, name) ||
- !git__prefixcmp(name, GIT_REFS_HEADS_DIR) ||
- !git__strcmp(name, GIT_HEAD_FILE) ||
- !git__prefixcmp(name, GIT_REFS_REMOTES_DIR) ||
- !git__prefixcmp(name, GIT_REFS_NOTES_DIR);
- break;
-
- case GIT_LOGALLREFUPDATES_ALWAYS:
- *write = 1;
- break;
- }
-
- return 0;
-}
static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name,
const git_oid *old_id, const char *old_target)
@@ -1220,54 +1184,28 @@
*/
static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
{
- int error;
+ git_reference *head = NULL;
+ git_refdb *refdb = NULL;
+ int error, write_reflog;
git_oid old_id;
- git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
- const char *name;
- if (ref->type == GIT_REFERENCE_SYMBOLIC)
- return 0;
+ 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)
- return error;
-
- if (git_reference_type(head) == GIT_REFERENCE_DIRECT)
- goto cleanup;
-
- if ((error = git_reference_lookup(&tmp, backend->repo, GIT_HEAD_FILE)) < 0)
- goto cleanup;
-
- /* Go down the symref chain until we find the branch */
- while (git_reference_type(tmp) == GIT_REFERENCE_SYMBOLIC) {
- error = git_reference_lookup(&peeled, backend->repo, git_reference_symbolic_target(tmp));
- if (error < 0)
- break;
-
- git_reference_free(tmp);
- tmp = peeled;
- }
-
- if (error == GIT_ENOTFOUND) {
- error = 0;
- name = git_reference_symbolic_target(tmp);
- } else if (error < 0) {
- goto cleanup;
- } else {
- name = git_reference_name(tmp);
- }
-
- if (strcmp(name, ref->name))
- goto cleanup;
-
- error = reflog_append(backend, head, &old_id, git_reference_target(ref), who, message);
+ 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;
-cleanup:
- git_reference_free(tmp);
+out:
git_reference_free(head);
+ git_refdb_free(refdb);
return error;
}
@@ -1284,7 +1222,7 @@
git_filebuf file = GIT_FILEBUF_INIT;
int error = 0;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = reference_path_available(backend, ref->name, NULL, force)) < 0)
return error;
@@ -1336,7 +1274,10 @@
}
if (update_reflog) {
- if ((error = should_write_reflog(&should_write, backend->repo, ref->name)) < 0)
+ 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) {
@@ -1354,7 +1295,7 @@
return error;
}
-static void refdb_fs_backend__prune_refs(
+static int refdb_fs_backend__prune_refs(
refdb_fs_backend *backend,
const char *ref_name,
const char *prefix)
@@ -1362,10 +1303,12 @@
git_buf relative_path = GIT_BUF_INIT;
git_buf base_path = GIT_BUF_INIT;
size_t commonlen;
+ int error;
- assert(backend && ref_name);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(ref_name);
- if (git_buf_sets(&relative_path, ref_name) < 0)
+ if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
goto cleanup;
git_path_squash_slashes(&relative_path);
@@ -1375,20 +1318,30 @@
git_buf_truncate(&relative_path, commonlen);
- if (prefix) {
- if (git_buf_join3(&base_path, '/', backend->commonpath, prefix, git_buf_cstr(&relative_path)) < 0)
- goto cleanup;
- } else {
- if (git_buf_joinpath(&base_path, backend->commonpath, git_buf_cstr(&relative_path)) < 0)
- goto cleanup;
- }
+ if (prefix)
+ error = git_buf_join3(&base_path, '/',
+ backend->commonpath, prefix,
+ git_buf_cstr(&relative_path));
+ else
+ error = git_buf_joinpath(&base_path,
+ backend->commonpath,
+ git_buf_cstr(&relative_path));
- git_futils_rmdir_r(ref_name + commonlen, git_buf_cstr(&base_path), GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
+ if (error < 0)
+ goto cleanup;
+
+ error = git_futils_rmdir_r(ref_name + commonlen,
+ git_buf_cstr(&base_path),
+ GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
+
+ if (error == GIT_ENOTFOUND)
+ error = 0;
}
cleanup:
git_buf_dispose(&relative_path);
git_buf_dispose(&base_path);
+ return error;
}
static int refdb_fs_backend__delete(
@@ -1400,7 +1353,8 @@
git_filebuf file = GIT_FILEBUF_INIT;
int error = 0;
- assert(backend && ref_name);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(ref_name);
if ((error = loose_lock(&file, backend, ref_name)) < 0)
return error;
@@ -1486,7 +1440,7 @@
cleanup:
git_filebuf_cleanup(file);
if (error == 0)
- refdb_fs_backend__prune_refs(backend, ref_name, "");
+ error = refdb_fs_backend__prune_refs(backend, ref_name, "");
return error;
}
@@ -1506,7 +1460,7 @@
git_filebuf file = GIT_FILEBUF_INIT;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = reference_path_available(
backend, new_name, old_name, force)) < 0 ||
@@ -1559,7 +1513,7 @@
int error;
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = packed_reload(backend)) < 0 || /* load the existing packfile */
(error = packed_loadloose(backend)) < 0 || /* add all the loose refs */
@@ -1573,7 +1527,8 @@
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- assert(backend);
+ if (!backend)
+ return;
git_sortedcache_free(backend->refcache);
git__free(backend->gitpath);
@@ -1734,7 +1689,7 @@
git_buf path = GIT_BUF_INIT;
int error;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend && name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo;
@@ -1767,7 +1722,8 @@
{
refdb_fs_backend *backend;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
@@ -1783,7 +1739,9 @@
git_repository *repo;
refdb_fs_backend *backend;
- assert(out && _backend && name);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo;
@@ -1900,7 +1858,8 @@
git_buf log = GIT_BUF_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
- assert(_backend && reflog);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(reflog);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
@@ -2022,7 +1981,9 @@
git_repository *repo;
refdb_fs_backend *backend;
- assert(_backend && old_name && new_name);
+ 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;
@@ -2099,7 +2060,8 @@
git_buf path = GIT_BUF_INIT;
int error;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
if ((error = retrieve_reflog_path(&path, backend->repo, name)) < 0)
goto out;
@@ -2110,7 +2072,7 @@
if ((error = p_unlink(path.ptr)) < 0)
goto out;
- refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
+ error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
out:
git_buf_dispose(&path);
diff -Nru cargo-0.47.0/debian/libgit2/src/refdb_fs.h cargo-0.51.0/debian/libgit2/src/refdb_fs.h
--- cargo-0.47.0/debian/libgit2/src/refdb_fs.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refdb_fs.h 1970-01-01 00:00:00.000000000 +0000
@@ -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_refdb_fs_h__
-#define INCLUDE_refdb_fs_h__
-
-#include "common.h"
-
-#include "strmap.h"
-
-typedef struct {
- git_strmap *packfile;
- time_t packfile_time;
-} git_refcache;
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/refdb.h cargo-0.51.0/debian/libgit2/src/refdb.h
--- cargo-0.47.0/debian/libgit2/src/refdb.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refdb.h 2021-04-07 03:36:48.000000000 +0000
@@ -30,6 +30,31 @@
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,
@@ -50,6 +75,50 @@
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);
diff -Nru cargo-0.47.0/debian/libgit2/src/reflog.c cargo-0.51.0/debian/libgit2/src/reflog.c
--- cargo-0.47.0/debian/libgit2/src/reflog.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/reflog.c 2021-04-07 03:36:48.000000000 +0000
@@ -12,12 +12,8 @@
#include "signature.h"
#include "refdb.h"
-#include
-
-git_reflog_entry *git_reflog_entry__alloc(void)
-{
- return git__calloc(1, sizeof(git_reflog_entry));
-}
+#include "git2/sys/refdb_backend.h"
+#include "git2/sys/reflog.h"
void git_reflog_entry__free(git_reflog_entry *entry)
{
@@ -54,7 +50,9 @@
git_refdb *refdb;
int error;
- assert(reflog && repo && name);
+ GIT_ASSERT_ARG(reflog);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
return error;
@@ -66,7 +64,8 @@
{
git_refdb *db;
- assert(reflog && reflog->db);
+ GIT_ASSERT_ARG(reflog);
+ GIT_ASSERT_ARG(reflog->db);
db = reflog->db;
return db->backend->reflog_write(db->backend, reflog);
@@ -77,7 +76,9 @@
const git_reflog_entry *previous;
git_reflog_entry *entry;
- assert(reflog && new_oid && committer);
+ 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);
@@ -143,13 +144,13 @@
size_t git_reflog_entrycount(git_reflog *reflog)
{
- assert(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)
+const git_reflog_entry *git_reflog_entry_byindex(const git_reflog *reflog, size_t idx)
{
- assert(reflog);
+ GIT_ASSERT_ARG_WITH_RETVAL(reflog, NULL);
if (idx >= reflog->entries.length)
return NULL;
@@ -158,27 +159,27 @@
&reflog->entries, reflog_inverse_index(idx, reflog->entries.length));
}
-const git_oid * git_reflog_entry_id_old(const git_reflog_entry *entry)
+const git_oid *git_reflog_entry_id_old(const git_reflog_entry *entry)
{
- assert(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)
+const git_oid *git_reflog_entry_id_new(const git_reflog_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return &entry->oid_cur;
}
-const git_signature * git_reflog_entry_committer(const git_reflog_entry *entry)
+const git_signature *git_reflog_entry_committer(const git_reflog_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return entry->committer;
}
-const char * git_reflog_entry_message(const git_reflog_entry *entry)
+const char *git_reflog_entry_message(const git_reflog_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return entry->msg;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/refs.c cargo-0.51.0/debian/libgit2/src/refs.c
--- cargo-0.47.0/debian/libgit2/src/refs.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refs.c 2021-04-07 03:36:48.000000000 +0000
@@ -27,9 +27,6 @@
bool git_reference__enable_symbolic_ref_target_validation = true;
-#define DEFAULT_NESTING_LEVEL 5
-#define MAX_NESTING_LEVEL 10
-
enum {
GIT_PACKREF_HAS_PEEL = 1,
GIT_PACKREF_WAS_LOOSE = 2
@@ -53,7 +50,8 @@
{
git_reference *ref;
- assert(name && target);
+ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(target, NULL);
ref = alloc_ref(name);
if (!ref)
@@ -76,7 +74,8 @@
{
git_reference *ref;
- assert(name && oid);
+ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(oid, NULL);
ref = alloc_ref(name);
if (!ref)
@@ -97,7 +96,8 @@
size_t namelen, reflen;
git_reference *rewrite = NULL;
- assert(ptr_to_ref && name);
+ GIT_ASSERT_ARG_WITH_RETVAL(ptr_to_ref, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
namelen = strlen(name);
@@ -214,92 +214,37 @@
const char *name,
int max_nesting)
{
- git_refname_t scan_name;
- git_reference_t scan_type;
- int error = 0, nesting;
- git_reference *ref = NULL;
+ git_refname_t normalized;
git_refdb *refdb;
+ int error = 0;
- assert(ref_out && repo && name);
-
- *ref_out = NULL;
-
- if (max_nesting > MAX_NESTING_LEVEL)
- max_nesting = MAX_NESTING_LEVEL;
- else if (max_nesting < 0)
- max_nesting = DEFAULT_NESTING_LEVEL;
-
- scan_type = GIT_REFERENCE_SYMBOLIC;
-
- if ((error = reference_normalize_for_repo(scan_name, repo, name, true)) < 0)
- return error;
-
- if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 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;
- for (nesting = max_nesting;
- nesting >= 0 && scan_type == GIT_REFERENCE_SYMBOLIC;
- nesting--)
- {
- if (nesting != max_nesting) {
- strncpy(scan_name, ref->target.symbolic, sizeof(scan_name));
- git_reference_free(ref);
- }
-
- if ((error = git_refdb_lookup(&ref, refdb, scan_name)) < 0)
- return error;
-
- scan_type = ref->type;
- }
-
- if (scan_type != GIT_REFERENCE_DIRECT && max_nesting != 0) {
- git_error_set(GIT_ERROR_REFERENCE,
- "cannot resolve reference (>%u levels deep)", max_nesting);
- git_reference_free(ref);
- return -1;
+ /*
+ * 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;
}
- *ref_out = ref;
return 0;
}
-int git_reference__read_head(
- git_reference **out,
- git_repository *repo,
- const char *path)
-{
- git_buf reference = GIT_BUF_INIT;
- char *name = NULL;
- int error;
-
- if ((error = git_futils_readbuffer(&reference, path)) < 0)
- goto out;
- git_buf_rtrim(&reference);
-
- if (git__strncmp(reference.ptr, GIT_SYMREF, strlen(GIT_SYMREF)) == 0) {
- git_buf_consume(&reference, reference.ptr + strlen(GIT_SYMREF));
-
- name = git_path_basename(path);
-
- if ((*out = git_reference__alloc_symbolic(name, reference.ptr)) == NULL) {
- error = -1;
- goto out;
- }
- } else {
- if ((error = git_reference_lookup(out, repo, reference.ptr)) < 0)
- goto out;
- }
-
-out:
- git__free(name);
- git_buf_dispose(&reference);
-
- return error;
-}
-
int git_reference_dwim(git_reference **out, git_repository *repo, const char *refname)
{
- int error = 0, i;
+ int error = 0, i, valid;
bool fallbackmode = true, foundvalid = false;
git_reference *ref;
git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
@@ -325,10 +270,11 @@
git_buf_clear(&refnamebuf);
- if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0)
+ if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0 ||
+ (error = git_reference_name_is_valid(&valid, git_buf_cstr(&refnamebuf))) < 0)
goto cleanup;
- if (!git_reference_is_valid_name(git_buf_cstr(&refnamebuf))) {
+ if (!valid) {
error = GIT_EINVALIDSPEC;
continue;
}
@@ -366,25 +312,25 @@
*/
git_reference_t git_reference_type(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG(ref);
return ref->type;
}
const char *git_reference_name(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
return ref->name;
}
git_repository *git_reference_owner(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
return ref->db->repo;
}
const git_oid *git_reference_target(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
if (ref->type != GIT_REFERENCE_DIRECT)
return NULL;
@@ -394,7 +340,7 @@
const git_oid *git_reference_target_peel(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel))
return NULL;
@@ -404,7 +350,7 @@
const char *git_reference_symbolic_target(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
if (ref->type != GIT_REFERENCE_SYMBOLIC)
return NULL;
@@ -429,8 +375,9 @@
git_reference *ref = NULL;
int error = 0;
- assert(repo && name);
- assert(symbolic || signature);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
+ GIT_ASSERT_ARG(symbolic || signature);
if (ref_out)
*ref_out = NULL;
@@ -444,7 +391,7 @@
return error;
if (oid != NULL) {
- assert(symbolic == NULL);
+ GIT_ASSERT(symbolic == NULL);
if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) {
git_error_set(GIT_ERROR_REFERENCE,
@@ -480,7 +427,7 @@
return 0;
}
-int configured_ident(git_signature **out, const git_repository *repo)
+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);
@@ -494,7 +441,7 @@
int error;
git_signature *who;
- if(((error = configured_ident(&who, repo)) < 0) &&
+ 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;
@@ -516,7 +463,7 @@
int error;
git_signature *who = NULL;
- assert(id);
+ GIT_ASSERT_ARG(id);
if ((error = git_reference__log_signature(&who, repo)) < 0)
return error;
@@ -551,7 +498,7 @@
int error;
git_signature *who = NULL;
- assert(target);
+ GIT_ASSERT_ARG(target);
if ((error = git_reference__log_signature(&who, repo)) < 0)
return error;
@@ -592,7 +539,9 @@
int error;
git_repository *repo;
- assert(out && ref && id);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ref);
+ GIT_ASSERT_ARG(id);
repo = ref->db->repo;
@@ -619,7 +568,9 @@
{
int error;
- assert(out && ref && target);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ref);
+ GIT_ASSERT_ARG(target);
if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0)
return error;
@@ -631,84 +582,33 @@
typedef struct {
const char *old_name;
git_refname_t new_name;
-} rename_cb_data;
+} refs_update_head_payload;
-static int update_wt_heads(git_repository *repo, const char *path, void *payload)
+static int refs_update_head(git_repository *worktree, void *_payload)
{
- rename_cb_data *data = (rename_cb_data *) payload;
- git_reference *head = NULL;
- char *gitdir = NULL;
+ refs_update_head_payload *payload = (refs_update_head_payload *)_payload;
+ git_reference *head = NULL, *updated = NULL;
int error;
- if ((error = git_reference__read_head(&head, repo, path)) < 0) {
- git_error_set(GIT_ERROR_REFERENCE, "could not read HEAD when renaming references");
- goto out;
- }
-
- if ((gitdir = git_path_dirname(path)) == NULL) {
- error = -1;
+ if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0)
goto out;
- }
if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC ||
- git__strcmp(head->target.symbolic, data->old_name) != 0) {
- error = 0;
+ git__strcmp(git_reference_symbolic_target(head), payload->old_name) != 0)
goto out;
- }
- /* Update HEAD it was pointing to the reference being renamed */
- if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) {
+ /* 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);
- git__free(gitdir);
-
- return error;
-}
-
-static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
- const git_signature *signature, const char *message)
-{
- git_repository *repo;
- git_refname_t normalized;
- bool should_head_be_updated = false;
- int error = 0;
-
- assert(ref && new_name && signature);
-
- repo = git_reference_owner(ref);
-
- if ((error = reference_normalize_for_repo(
- normalized, repo, new_name, true)) < 0)
- return error;
-
- /* Check if we have to update HEAD. */
- if ((error = git_branch_is_head(ref)) < 0)
- return error;
-
- should_head_be_updated = (error > 0);
-
- if ((error = git_refdb_rename(out, ref->db, ref->name, normalized, force, signature, message)) < 0)
- return error;
-
- /* Update HEAD if it was pointing to the reference being renamed */
- if (should_head_be_updated) {
- error = git_repository_set_head(ref->db->repo, normalized);
- } else {
- rename_cb_data payload;
- payload.old_name = ref->name;
- memcpy(&payload.new_name, &normalized, sizeof(normalized));
-
- error = git_repository_foreach_head(repo, update_wt_heads, 0, &payload);
- }
-
return error;
}
-
int git_reference_rename(
git_reference **out,
git_reference *ref,
@@ -716,17 +616,29 @@
int force,
const char *log_message)
{
- git_signature *who;
+ refs_update_head_payload payload;
+ git_signature *signature = NULL;
+ git_repository *repo;
int error;
- assert(out && ref);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(ref);
- if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
- return error;
+ repo = git_reference_owner(ref);
- error = reference__rename(out, ref, new_name, force, who, log_message);
- git_signature_free(who);
+ 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;
}
@@ -876,7 +788,8 @@
{
git_vector ref_list;
- assert(array && repo);
+ GIT_ASSERT_ARG(array);
+ GIT_ASSERT_ARG(repo);
array->strings = NULL;
array->count = 0;
@@ -960,7 +873,8 @@
size_t i;
char c;
- assert(name && len > 0);
+ GIT_ASSERT_ARG(name);
+ GIT_ASSERT_ARG(len > 0);
for (i = 0; i < len; i++)
{
@@ -991,7 +905,7 @@
git_path_iconv_t ic = GIT_PATH_ICONV_INIT;
#endif
- assert(name);
+ GIT_ASSERT_ARG(name);
process_flags = flags;
current = (char *)name;
@@ -1123,7 +1037,8 @@
goto cleanup;
}
- git_buf_copy_cstr(buffer_out, buffer_size, &buf);
+ if ((error = git_buf_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
+ goto cleanup;
error = 0;
@@ -1139,7 +1054,9 @@
const git_reference *ref2)
{
git_reference_t type1, type2;
- assert(ref1 && ref2);
+
+ GIT_ASSERT_ARG(ref1);
+ GIT_ASSERT_ARG(ref2);
type1 = git_reference_type(ref1);
type2 = git_reference_type(ref2);
@@ -1154,40 +1071,6 @@
return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
}
-/**
- * Get the end of a chain of references. If the final one is not
- * found, we return the reference just before that.
- */
-static int get_terminal(git_reference **out, git_repository *repo, const char *ref_name, int nesting)
-{
- git_reference *ref;
- int error = 0;
-
- if (nesting > MAX_NESTING_LEVEL) {
- git_error_set(GIT_ERROR_REFERENCE, "reference chain too deep (%d)", nesting);
- return GIT_ENOTFOUND;
- }
-
- /* set to NULL to let the caller know that they're at the end of the chain */
- if ((error = git_reference_lookup(&ref, repo, ref_name)) < 0) {
- *out = NULL;
- return error;
- }
-
- if (git_reference_type(ref) == GIT_REFERENCE_DIRECT) {
- *out = ref;
- error = 0;
- } else {
- error = get_terminal(out, repo, git_reference_symbolic_target(ref), nesting + 1);
- if (error == GIT_ENOTFOUND && !*out)
- *out = ref;
- else
- git_reference_free(ref);
- }
-
- return error;
-}
-
/*
* Starting with the reference given by `ref_name`, follows symbolic
* references until a direct reference is found and updated the OID
@@ -1202,31 +1085,37 @@
{
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)
- return error;
+ goto out;
to_use = sig ? sig : who;
- error = get_terminal(&ref, repo, ref_name, 0);
- /* found a dangling symref */
- if (error == GIT_ENOTFOUND && ref) {
- assert(git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC);
- git_error_clear();
+ 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 if (error == GIT_ENOTFOUND) {
- git_error_clear();
- error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use,
- log_message, NULL, NULL);
- } else if (error == 0) {
- assert(git_reference_type(ref) == GIT_REFERENCE_DIRECT);
+ } 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);
@@ -1290,7 +1179,8 @@
int error;
git_refdb *refdb;
- assert(repo && refname);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refname);
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
return error;
@@ -1303,7 +1193,8 @@
int error;
git_refdb *refdb;
- assert(repo && refname);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refname);
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
return error;
@@ -1318,7 +1209,7 @@
int git_reference_is_branch(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG(ref);
return git_reference__is_branch(ref->name);
}
@@ -1329,7 +1220,7 @@
int git_reference_is_remote(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG(ref);
return git_reference__is_remote(ref->name);
}
@@ -1340,7 +1231,7 @@
int git_reference_is_tag(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG(ref);
return git_reference__is_tag(ref->name);
}
@@ -1351,7 +1242,7 @@
int git_reference_is_note(const git_reference *ref)
{
- assert(ref);
+ GIT_ASSERT_ARG(ref);
return git_reference__is_note(ref->name);
}
@@ -1373,7 +1264,7 @@
git_object *target = NULL;
int error;
- assert(ref);
+ GIT_ASSERT_ARG(ref);
if (ref->type == GIT_REFERENCE_DIRECT) {
resolved = ref;
@@ -1415,19 +1306,30 @@
return error;
}
-int git_reference__is_valid_name(const char *refname, unsigned int flags)
+int git_reference__name_is_valid(
+ int *valid,
+ const char *refname,
+ unsigned int flags)
{
- if (git_reference__normalize_name(NULL, refname, flags) < 0) {
- git_error_clear();
- return false;
- }
+ int error;
- return true;
+ 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_is_valid_name(const char *refname)
+int git_reference_name_is_valid(int *valid, const char *refname)
{
- return git_reference__is_valid_name(refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL);
+ return git_reference__name_is_valid(valid, refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL);
}
const char *git_reference__shorthand(const char *name)
@@ -1454,7 +1356,10 @@
{
int error;
git_reference *tmp_ref;
- assert(unborn && ref && repo);
+
+ GIT_ASSERT_ARG(unborn);
+ GIT_ASSERT_ARG(ref);
+ GIT_ASSERT_ARG(repo);
if (ref->type == GIT_REFERENCE_DIRECT) {
*unborn = 0;
@@ -1473,3 +1378,18 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/refs.h cargo-0.51.0/debian/libgit2/src/refs.h
--- cargo-0.47.0/debian/libgit2/src/refs.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refs.h 2021-04-07 03:36:48.000000000 +0000
@@ -45,7 +45,6 @@
#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_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
#define GIT_SEQUENCER_DIR "sequencer/"
#define GIT_SEQUENCER_HEAD_FILE GIT_SEQUENCER_DIR "head"
@@ -86,10 +85,11 @@
int git_reference__normalize_name(git_buf *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__is_valid_name(const char *refname, unsigned int flags);
+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);
/**
@@ -115,24 +115,6 @@
const char *name,
int max_deref);
-/**
- * Read reference from a file.
- *
- * This function will read in the file at `path`. If it is a
- * symref, it will return a new unresolved symbolic reference
- * with the given name pointing to the reference pointed to by
- * the file. If it is not a symbolic reference, it will return
- * the resolved reference.
- *
- * Note that because the refdb is not involved for symbolic references, they
- * won't be owned, hence you should either not make the returned reference
- * 'externally visible', or perform the lookup before returning it to the user.
- */
-int git_reference__read_head(
- git_reference **out,
- git_repository *repo,
- const char *path);
-
int git_reference__log_signature(git_signature **out, git_repository *repo);
/** Update a reference after a commit. */
diff -Nru cargo-0.47.0/debian/libgit2/src/refspec.c cargo-0.51.0/debian/libgit2/src/refspec.c
--- cargo-0.47.0/debian/libgit2/src/refspec.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/refspec.c 2021-04-07 03:36:48.000000000 +0000
@@ -21,9 +21,11 @@
size_t llen;
int is_glob = 0;
const char *lhs, *rhs;
- int flags;
+ int valid = 0;
+ unsigned int flags;
- assert(refspec && input);
+ GIT_ASSERT_ARG(refspec);
+ GIT_ASSERT_ARG(input);
memset(refspec, 0x0, sizeof(git_refspec));
refspec->push = !is_fetch;
@@ -75,57 +77,69 @@
if (is_fetch) {
/*
- * LHS
- * - empty is allowed; it means HEAD.
- * - otherwise it must be a valid looking ref.
- */
+ * 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__is_valid_name(refspec->src, flags))
+ 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.
- */
+ * 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__is_valid_name(refspec->dst, flags))
+ 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.
- */
+ * 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__is_valid_name(refspec->src, flags))
+ 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.
- */
+ * 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__is_valid_name(refspec->src, flags))
+ 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__is_valid_name(refspec->dst, flags))
+ if (git_reference__name_is_valid(&valid, refspec->dst, flags) < 0)
+ goto on_error;
+ else if (!valid)
goto invalid;
}
@@ -141,11 +155,14 @@
return 0;
- invalid:
- git_error_set(
- GIT_ERROR_INVALID,
- "'%s' is not a valid refspec.", input);
- git_refspec__dispose(refspec);
+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;
}
@@ -164,7 +181,8 @@
int git_refspec_parse(git_refspec **out_refspec, const char *input, int is_fetch)
{
git_refspec *refspec;
- assert(out_refspec && input);
+ GIT_ASSERT_ARG(out_refspec);
+ GIT_ASSERT_ARG(input);
*out_refspec = NULL;
@@ -203,7 +221,7 @@
int git_refspec_force(const git_refspec *refspec)
{
- assert(refspec);
+ GIT_ASSERT_ARG(refspec);
return refspec->force;
}
@@ -229,8 +247,11 @@
{
const char *from_star, *to_star;
size_t replacement_len, star_offset;
+ int error;
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
- git_buf_sanitize(out);
git_buf_clear(out);
/*
@@ -242,7 +263,7 @@
from_star = strchr(from, '*');
to_star = strchr(to, '*');
- assert(from_star && to_star);
+ GIT_ASSERT(from_star && to_star);
/* star offset, both in 'from' and in 'name' */
star_offset = from_star - from;
@@ -262,8 +283,14 @@
int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{
- assert(out && spec && name);
- git_buf_sanitize(out);
+ int error;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(name);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (!git_refspec_src_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the source", name);
@@ -278,8 +305,14 @@
int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{
- assert(out && spec && name);
- git_buf_sanitize(out);
+ int error;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(name);
+
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (!git_refspec_dst_matches(spec, name)) {
git_error_set(GIT_ERROR_INVALID, "ref '%s' doesn't match the destination", name);
@@ -306,14 +339,15 @@
int git_refspec_is_wildcard(const git_refspec *spec)
{
- assert(spec && spec->src);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(spec->src);
return (spec->src[strlen(spec->src) - 1] == '*');
}
git_direction git_refspec_direction(const git_refspec *spec)
{
- assert(spec);
+ GIT_ASSERT_ARG(spec);
return spec->push;
}
@@ -332,7 +366,9 @@
NULL
};
- assert(out && spec && refs);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(refs);
cur = git__calloc(1, sizeof(git_refspec));
GIT_ERROR_CHECK_ALLOC(cur);
diff -Nru cargo-0.47.0/debian/libgit2/src/regexp.c cargo-0.51.0/debian/libgit2/src/regexp.c
--- cargo-0.47.0/debian/libgit2/src/regexp.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/regexp.c 2021-04-07 03:36:48.000000000 +0000
@@ -12,7 +12,7 @@
int git_regexp_compile(git_regexp *r, const char *pattern, int flags)
{
int erroffset, cflags = 0;
- const char *error;
+ const char *error = NULL;
if (flags & GIT_REGEXP_ICASE)
cflags |= PCRE_CASELESS;
@@ -41,7 +41,7 @@
int git_regexp_search(const git_regexp *r, const char *string, size_t nmatches, git_regmatch *matches)
{
- int static_ovec[9], *ovec;
+ int static_ovec[9] = {0}, *ovec;
int error;
size_t i;
diff -Nru cargo-0.47.0/debian/libgit2/src/remote.c cargo-0.51.0/debian/libgit2/src/remote.c
--- cargo-0.47.0/debian/libgit2/src/remote.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/remote.c 2021-04-07 03:36:48.000000000 +0000
@@ -82,9 +82,11 @@
static int ensure_remote_name_is_valid(const char *name)
{
- int error = 0;
+ int valid, error;
+
+ error = git_remote_name_is_valid(&valid, name);
- if (!git_remote_is_valid_name(name)) {
+ if (!error && !valid) {
git_error_set(
GIT_ERROR_CONFIG,
"'%s' is not a valid remote name.", name ? name : "(null)");
@@ -110,12 +112,8 @@
if ((error = ensure_remote_name_is_valid(name)) < 0)
return error;
- if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0) {
- if (git_error_last()->klass != GIT_ERROR_NOMEMORY)
- error = GIT_EINVALIDSPEC;
-
+ if ((error = git_refspec__parse(&spec, refspec, fetch)) < 0)
return error;
- }
git_refspec__dispose(&spec);
@@ -195,10 +193,12 @@
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)
{
@@ -210,7 +210,8 @@
const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
int error = -1;
- assert(out && url);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(url);
if (!opts) {
opts = &dummy_opts;
@@ -459,7 +460,9 @@
struct refspec_cb_data data = { NULL };
bool optional_setting_found = false, found;
- assert(out && repo && name);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
if ((error = ensure_remote_name_is_valid(name)) < 0)
return error;
@@ -581,19 +584,19 @@
const char *git_remote_name(const git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL);
return remote->name;
}
git_repository *git_remote_owner(const git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL);
return remote->repo;
}
const char *git_remote_url(const git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL);
return remote->url;
}
@@ -603,7 +606,8 @@
git_buf buf = GIT_BUF_INIT, canonical_url = GIT_BUF_INIT;
int error;
- assert(repo && remote);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(remote);
if ((error = ensure_remote_name_is_valid(remote)) < 0)
return error;
@@ -637,7 +641,7 @@
const char *git_remote_pushurl(const git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL);
return remote->pushurl;
}
@@ -648,14 +652,17 @@
static int resolve_url(git_buf *resolved_url, const char *url, int direction, const git_remote_callbacks *callbacks)
{
- int status;
+ int status, error;
if (callbacks && callbacks->resolve_url) {
git_buf_clear(resolved_url);
status = callbacks->resolve_url(resolved_url, url, direction, callbacks->payload);
if (status != GIT_PASSTHROUGH) {
git_error_set_after_callback_function(status, "git_resolve_url_cb");
- git_buf_sanitize(resolved_url);
+
+ if ((error = git_buf_sanitize(resolved_url)) < 0)
+ return error;
+
return status;
}
}
@@ -667,8 +674,8 @@
{
const char *url = NULL;
- assert(remote);
- assert(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH);
+ GIT_ASSERT_ARG(remote);
+ GIT_ASSERT_ARG(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH);
if (direction == GIT_DIRECTION_FETCH) {
url = remote->url;
@@ -686,7 +693,7 @@
return resolve_url(url_out, url, direction, callbacks);
}
-int set_transport_callbacks(git_transport *t, const git_remote_callbacks *cbs)
+static int remote_transport_set_callbacks(git_transport *t, const git_remote_callbacks *cbs)
{
if (!t->set_callbacks || !cbs)
return 0;
@@ -713,7 +720,7 @@
git_credential_acquire_cb credentials = NULL;
git_transport_cb transport = NULL;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (callbacks) {
GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
@@ -744,7 +751,7 @@
if ((error = set_transport_custom_headers(t, conn->custom_headers)) != 0)
goto on_error;
- if ((error = set_transport_callbacks(t, callbacks)) < 0 ||
+ if ((error = remote_transport_set_callbacks(t, callbacks)) < 0 ||
(error = t->connect(t, url.ptr, credentials, payload, conn->proxy, direction, flags)) != 0)
goto on_error;
@@ -778,7 +785,7 @@
int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!remote->transport) {
git_error_set(GIT_ERROR_NET, "this remote has never connected");
@@ -795,7 +802,7 @@
git_buf val = GIT_BUF_INIT;
int error;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!proxy_url || !remote->repo)
return -1;
@@ -924,7 +931,7 @@
const git_strarray *custom_headers = NULL;
const git_proxy_options *proxy = NULL;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!remote->repo) {
git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
@@ -1063,7 +1070,8 @@
unsigned int i;
git_remote_head *remote_ref;
- assert(update_heads && fetchspec_src);
+ GIT_ASSERT_ARG(update_heads);
+ GIT_ASSERT_ARG(fetchspec_src);
*out = NULL;
@@ -1117,7 +1125,9 @@
const char *ref_name;
int error = 0, update;
- assert(out && spec && ref);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(spec);
+ GIT_ASSERT_ARG(ref);
*out = NULL;
@@ -1154,7 +1164,7 @@
unsigned int i = 0;
int error = 0;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
/* no heads, nothing to do */
if (update_heads->length == 0)
@@ -1237,7 +1247,7 @@
}
out:
- git_strarray_free(&arr);
+ git_strarray_dispose(&arr);
return error;
}
@@ -1360,7 +1370,7 @@
git_vector *refs,
const char *log_message)
{
- int error = 0, autotag;
+ int error = 0, autotag, valid;
unsigned int i = 0;
git_buf refname = GIT_BUF_INIT;
git_oid old;
@@ -1370,7 +1380,7 @@
git_refspec tagspec;
git_vector update_heads;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (git_repository_odb__weakptr(&odb, remote->repo) < 0)
return -1;
@@ -1388,7 +1398,10 @@
git_buf_clear(&refname);
/* Ignore malformed ref names (which also saves us from tag^{} */
- if (!git_reference_is_valid_name(head->name))
+ if (git_reference_name_is_valid(&valid, head->name) < 0)
+ goto on_error;
+
+ if (!valid)
continue;
/* If we have a tag, see if the auto-follow rules say to update it */
@@ -1497,6 +1510,7 @@
git_remote_head *head;
git_refspec *spec, *passive_spec;
size_t i, j, k;
+ int valid;
active = &remote->active_refspecs;
passive = &remote->passive_refspecs;
@@ -1508,7 +1522,10 @@
for (; i < refs->length; i++) {
head = git_vector_get(refs, i);
- if (!git_reference_is_valid_name(head->name))
+ if (git_reference_name_is_valid(&valid, head->name) < 0)
+ return -1;
+
+ if (!valid)
continue;
for (; j < active->length; j++) {
@@ -1667,7 +1684,7 @@
int git_remote_connected(const git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!remote->transport || !remote->transport->is_connected)
return 0;
@@ -1678,7 +1695,7 @@
int git_remote_stop(git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (remote->transport && remote->transport->cancel)
remote->transport->cancel(remote->transport);
@@ -1688,7 +1705,7 @@
int git_remote_disconnect(git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (git_remote_connected(remote))
remote->transport->close(remote->transport);
@@ -1774,7 +1791,7 @@
const git_indexer_progress *git_remote_stats(git_remote *remote)
{
- assert(remote);
+ GIT_ASSERT_ARG_WITH_RETVAL(remote, NULL);
return &remote->stats;
}
@@ -1789,7 +1806,7 @@
git_config *config;
int error;
- assert(repo && remote);
+ GIT_ASSERT_ARG(repo && remote);
if ((error = ensure_remote_name_is_valid(remote)) < 0)
return error;
@@ -2053,7 +2070,7 @@
git_vector problem_refspecs = GIT_VECTOR_INIT;
git_remote *remote = NULL;
- assert(out && repo && name && new_name);
+ GIT_ASSERT_ARG(out && repo && name && new_name);
if ((error = git_remote_lookup(&remote, repo, name)) < 0)
return error;
@@ -2087,24 +2104,34 @@
return error;
}
-int git_remote_is_valid_name(
- const char *remote_name)
+int git_remote_name_is_valid(int *valid, const char *remote_name)
{
git_buf buf = GIT_BUF_INIT;
- git_refspec refspec;
- int error = -1;
+ git_refspec refspec = {0};
+ int error;
+
+ GIT_ASSERT(valid);
+
+ *valid = 0;
if (!remote_name || *remote_name == '\0')
return 0;
- git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name);
+ if ((error = git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name)) < 0)
+ goto done;
+
error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
+ if (!error)
+ *valid = 1;
+ else if (error == GIT_EINVALIDSPEC)
+ error = 0;
+
+done:
git_buf_dispose(&buf);
git_refspec__dispose(&refspec);
- git_error_clear();
- return error == 0;
+ return error;
}
git_refspec *git_remote__matching_refspec(git_remote *remote, const char *refname)
@@ -2219,7 +2246,7 @@
prefix_len = strlen("remote.");
dot = strchr(name + prefix_len, '.');
- assert(dot);
+ GIT_ASSERT_ARG_WITH_RETVAL(dot, NULL);
*len_out = dot - name - prefix_len;
return name + prefix_len;
@@ -2249,10 +2276,13 @@
if (strcmp(remote_name, entry->value))
continue;
- branch = name_offset(&branch_len, entry->name);
+ if ((branch = name_offset(&branch_len, entry->name)) == NULL) {
+ error = -1;
+ break;
+ }
git_buf_clear(&buf);
- if (git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch) < 0)
+ if ((error = git_buf_printf(&buf, "branch.%.*s.merge", (int)branch_len, branch)) < 0)
break;
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
@@ -2262,7 +2292,7 @@
}
git_buf_clear(&buf);
- if (git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch) < 0)
+ if ((error = git_buf_printf(&buf, "branch.%.*s.remote", (int)branch_len, branch)) < 0)
break;
if ((error = git_config_delete_entry(config, git_buf_cstr(&buf))) < 0) {
@@ -2357,7 +2387,8 @@
{
int error;
- assert(repo && name);
+ 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 ||
@@ -2373,29 +2404,37 @@
const git_remote_head *guess = NULL;
const git_oid *head_id;
size_t heads_len, i;
+ git_buf local_default = GIT_BUF_INIT;
int error;
- assert(out);
+ GIT_ASSERT_ARG(out);
if ((error = git_remote_ls(&heads, &heads_len, remote)) < 0)
- return error;
+ goto done;
- if (heads_len == 0)
- return GIT_ENOTFOUND;
+ if (heads_len == 0 || strcmp(heads[0]->name, GIT_HEAD_FILE)) {
+ error = GIT_ENOTFOUND;
+ goto done;
+ }
- if (strcmp(heads[0]->name, GIT_HEAD_FILE))
- return GIT_ENOTFOUND;
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
- git_buf_sanitize(out);
/* the first one must be HEAD so if that has the symref info, we're done */
- if (heads[0]->symref_target)
- return git_buf_puts(out, heads[0]->symref_target);
+ if (heads[0]->symref_target) {
+ error = git_buf_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 master
- * branch is a candidate. Then we return the master branch.
+ * 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++) {
@@ -2410,16 +2449,22 @@
continue;
}
- if (!git__strcmp(GIT_REFS_HEADS_MASTER_FILE, heads[i]->name)) {
+ if (!git__strcmp(local_default.ptr, heads[i]->name)) {
guess = heads[i];
break;
}
}
- if (!guess)
- return GIT_ENOTFOUND;
+ if (!guess) {
+ error = GIT_ENOTFOUND;
+ goto done;
+ }
+
+ error = git_buf_puts(out, guess->name);
- return git_buf_puts(out, guess->name);
+done:
+ git_buf_dispose(&local_default);
+ return error;
}
int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
@@ -2431,7 +2476,7 @@
const git_remote_callbacks *cbs = NULL;
git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!remote->repo) {
git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
@@ -2497,7 +2542,7 @@
const git_strarray *custom_headers = NULL;
const git_proxy_options *proxy = NULL;
- assert(remote);
+ GIT_ASSERT_ARG(remote);
if (!remote->repo) {
git_error_set(GIT_ERROR_INVALID, "cannot download detached remote");
@@ -2512,8 +2557,6 @@
proxy = &opts->proxy_opts;
}
- assert(remote);
-
if ((error = git_remote_connect(remote, GIT_DIRECTION_PUSH, cbs, proxy, custom_headers)) < 0)
return error;
@@ -2540,9 +2583,9 @@
git_config_entry *entry;
git_config_iterator *iter;
- assert(config);
- assert(url);
- assert(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH);
+ GIT_ASSERT_ARG_WITH_RETVAL(config, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(url, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH, NULL);
/* Add 1 to prefix/suffix length due to the additional escaped dot */
prefix_length = strlen(PREFIX) + 1;
@@ -2590,3 +2633,17 @@
return result.ptr;
}
+
+/* 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 -Nru cargo-0.47.0/debian/libgit2/src/repository.c cargo-0.51.0/debian/libgit2/src/repository.c
--- cargo-0.47.0/debian/libgit2/src/repository.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/repository.c 2021-04-07 03:36:48.000000000 +0000
@@ -62,16 +62,18 @@
{ GIT_REPOSITORY_ITEM_COMMONDIR, GIT_REPOSITORY_ITEM_GITDIR, "worktrees", true }
};
-static int check_repositoryformatversion(git_config *config);
+static int check_repositoryformatversion(int *version, git_config *config);
+static int check_extensions(git_config *config, int version);
#define GIT_COMMONDIR_FILE "commondir"
#define GIT_GITDIR_FILE "gitdir"
#define GIT_FILE_CONTENT_PREFIX "gitdir:"
-#define GIT_BRANCH_MASTER "master"
+#define GIT_BRANCH_DEFAULT "master"
#define GIT_REPO_VERSION 0
+#define GIT_REPO_MAX_VERSION 1
git_buf git_repository__reserved_names_win32[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
@@ -91,7 +93,7 @@
GIT_REFCOUNT_INC(odb);
}
- if ((odb = git__swap(repo->_odb, odb)) != NULL) {
+ if ((odb = git_atomic_swap(repo->_odb, odb)) != NULL) {
GIT_REFCOUNT_OWN(odb, NULL);
git_odb_free(odb);
}
@@ -104,7 +106,7 @@
GIT_REFCOUNT_INC(refdb);
}
- if ((refdb = git__swap(repo->_refdb, refdb)) != NULL) {
+ if ((refdb = git_atomic_swap(repo->_refdb, refdb)) != NULL) {
GIT_REFCOUNT_OWN(refdb, NULL);
git_refdb_free(refdb);
}
@@ -117,7 +119,7 @@
GIT_REFCOUNT_INC(config);
}
- if ((config = git__swap(repo->_config, config)) != NULL) {
+ if ((config = git_atomic_swap(repo->_config, config)) != NULL) {
GIT_REFCOUNT_OWN(config, NULL);
git_config_free(config);
}
@@ -132,7 +134,7 @@
GIT_REFCOUNT_INC(index);
}
- if ((index = git__swap(repo->_index, index)) != NULL) {
+ if ((index = git_atomic_swap(repo->_index, index)) != NULL) {
GIT_REFCOUNT_OWN(index, NULL);
git_index_free(index);
}
@@ -140,7 +142,7 @@
int git_repository__cleanup(git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
git_repository_submodule_cache_clear(repo);
git_cache_clear(&repo->objects);
@@ -366,7 +368,7 @@
const char *ceil, *sep;
size_t len, max_len = 0, min_len;
- assert(path);
+ GIT_ASSERT_ARG(path);
min_len = (size_t)(git_path_root(path) + 1);
@@ -412,7 +414,8 @@
git_buf file = GIT_BUF_INIT;
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
- assert(path_out && file_path);
+ GIT_ASSERT_ARG(path_out);
+ GIT_ASSERT_ARG(file_path);
if (git_futils_readbuffer(&file, file_path) < 0)
return -1;
@@ -813,6 +816,7 @@
gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
git_repository *repo = NULL;
git_config *config = NULL;
+ int version = 0;
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
return _git_repository_open_ext_from_env(repo_ptr, start_path);
@@ -854,7 +858,10 @@
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
- if (config && (error = check_repositoryformatversion(config)) < 0)
+ if (config && (error = check_repositoryformatversion(&version, config)) < 0)
+ goto cleanup;
+
+ if ((error = check_extensions(config, version)) < 0)
goto cleanup;
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
@@ -895,7 +902,8 @@
size_t len;
int err;
- assert(repo_out && wt);
+ GIT_ASSERT_ARG(repo_out);
+ GIT_ASSERT_ARG(wt);
*repo_out = NULL;
len = strlen(wt->gitlink_path);
@@ -939,10 +947,12 @@
const char *ceiling_dirs)
{
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
+ int error;
- assert(start_path);
+ GIT_ASSERT_ARG(start_path);
- git_buf_sanitize(out);
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
}
@@ -959,7 +969,7 @@
git_buf config_path = GIT_BUF_INIT;
git_config *cfg = NULL;
- assert(out);
+ GIT_ASSERT_ARG(out);
if ((error = git_config_new(&cfg)) < 0)
return error;
@@ -1044,7 +1054,7 @@
if (!error) {
GIT_REFCOUNT_OWN(config, repo);
- config = git__compare_and_swap(&repo->_config, NULL, config);
+ config = git_atomic_compare_and_swap(&repo->_config, NULL, config);
if (config != NULL) {
GIT_REFCOUNT_OWN(config, NULL);
git_config_free(config);
@@ -1083,7 +1093,9 @@
int git_repository_set_config(git_repository *repo, git_config *config)
{
- assert(repo && config);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(config);
+
set_config(repo, config);
return 0;
}
@@ -1092,9 +1104,11 @@
{
int error = 0;
- assert(repo && out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(out);
- if (repo->_odb == NULL) {
+ *out = git_atomic_load(repo->_odb);
+ if (*out == NULL) {
git_buf odb_path = GIT_BUF_INIT;
git_odb *odb;
@@ -1111,16 +1125,16 @@
return error;
}
- odb = git__compare_and_swap(&repo->_odb, NULL, odb);
+ odb = git_atomic_compare_and_swap(&repo->_odb, NULL, odb);
if (odb != NULL) {
GIT_REFCOUNT_OWN(odb, NULL);
git_odb_free(odb);
}
git_buf_dispose(&odb_path);
+ *out = git_atomic_load(repo->_odb);
}
- *out = repo->_odb;
return error;
}
@@ -1135,7 +1149,9 @@
int git_repository_set_odb(git_repository *repo, git_odb *odb)
{
- assert(repo && odb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(odb);
+
set_odb(repo, odb);
return 0;
}
@@ -1144,7 +1160,8 @@
{
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
if (repo->_refdb == NULL) {
git_refdb *refdb;
@@ -1153,7 +1170,7 @@
if (!error) {
GIT_REFCOUNT_OWN(refdb, repo);
- refdb = git__compare_and_swap(&repo->_refdb, NULL, refdb);
+ refdb = git_atomic_compare_and_swap(&repo->_refdb, NULL, refdb);
if (refdb != NULL) {
GIT_REFCOUNT_OWN(refdb, NULL);
git_refdb_free(refdb);
@@ -1176,7 +1193,9 @@
int git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
{
- assert(repo && refdb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refdb);
+
set_refdb(repo, refdb);
return 0;
}
@@ -1185,7 +1204,8 @@
{
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
if (repo->_index == NULL) {
git_buf index_path = GIT_BUF_INIT;
@@ -1198,7 +1218,7 @@
if (!error) {
GIT_REFCOUNT_OWN(index, repo);
- index = git__compare_and_swap(&repo->_index, NULL, index);
+ index = git_atomic_compare_and_swap(&repo->_index, NULL, index);
if (index != NULL) {
GIT_REFCOUNT_OWN(index, NULL);
git_index_free(index);
@@ -1226,7 +1246,7 @@
int git_repository_set_index(git_repository *repo, git_index *index)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
set_index(repo, index);
return 0;
}
@@ -1350,11 +1370,11 @@
}
#endif
-static int check_repositoryformatversion(git_config *config)
+static int check_repositoryformatversion(int *version, git_config *config)
{
- int version, error;
+ int error;
- error = git_config_get_int32(&version, config, "core.repositoryformatversion");
+ 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;
@@ -1362,16 +1382,35 @@
if (error < 0)
return -1;
- if (GIT_REPO_VERSION < version) {
+ if (GIT_REPO_MAX_VERSION < *version) {
git_error_set(GIT_ERROR_REPOSITORY,
- "unsupported repository version %d. Only versions up to %d are supported.",
- version, GIT_REPO_VERSION);
+ "unsupported repository version %d; only versions up to %d are supported",
+ *version, GIT_REPO_MAX_VERSION);
return -1;
}
return 0;
}
+static int check_valid_extension(const git_config_entry *entry, void *payload)
+{
+ GIT_UNUSED(payload);
+
+ if (!strcmp(entry->name, "extensions.noop"))
+ return 0;
+
+ git_error_set(GIT_ERROR_REPOSITORY, "unsupported extension name %s", entry->name);
+ return -1;
+}
+
+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);
+}
+
int git_repository_create_head(const char *git_dir, const char *ref_name)
{
git_buf ref_path = GIT_BUF_INIT;
@@ -1383,9 +1422,6 @@
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
goto out;
- if (!ref_name)
- ref_name = GIT_BRANCH_MASTER;
-
if (git__prefixcmp(ref_name, GIT_REFS_DIR) == 0)
fmt = "ref: %s\n";
else
@@ -1583,11 +1619,15 @@
git_config *config = NULL;
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
+ int version = 0;
if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
goto cleanup;
- if (is_reinit && (error = check_repositoryformatversion(config)) < 0)
+ 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 { \
@@ -2032,6 +2072,43 @@
return error;
}
+static int repo_init_head(const char *repo_dir, const char *given)
+{
+ git_config *cfg = NULL;
+ git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
+ const char *initial_head = NULL;
+ int error;
+
+ if ((error = git_buf_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_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) {
+ 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_buf_dispose(&head_path);
+ git_buf_dispose(&cfg_branch);
+
+ return error;
+}
+
static int repo_init_create_origin(git_repository *repo, const char *url)
{
int error;
@@ -2062,12 +2139,14 @@
git_repository_init_options *opts)
{
git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
- common_path = GIT_BUF_INIT, head_path = GIT_BUF_INIT;
+ common_path = GIT_BUF_INIT;
const char *wd;
bool is_valid;
int error;
- assert(out && given_repo && opts);
+ 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");
@@ -2096,16 +2175,7 @@
} else {
if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
(error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 ||
- (error = git_buf_joinpath(&head_path, repo_path.ptr, GIT_HEAD_FILE)) < 0)
- goto out;
-
- /*
- * Only set the new HEAD if the file does not exist already via
- * a template or if the caller has explicitly supplied an
- * initial HEAD value.
- */
- if ((!git_path_exists(head_path.ptr) || opts->initial_head) &&
- (error = git_repository_create_head(repo_path.ptr, opts->initial_head)) < 0)
+ (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
goto out;
}
@@ -2117,7 +2187,6 @@
goto out;
out:
- git_buf_dispose(&head_path);
git_buf_dispose(&common_path);
git_buf_dispose(&repo_path);
git_buf_dispose(&wd_path);
@@ -2148,18 +2217,13 @@
return exists;
}
-static int get_worktree_file_path(git_buf *out, git_repository *repo, const char *worktree, const char *file)
-{
- git_buf_clear(out);
- return git_buf_printf(out, "%s/worktrees/%s/%s", repo->commondir, worktree, file);
-}
-
int git_repository_head_detached_for_worktree(git_repository *repo, const char *name)
{
git_reference *ref = NULL;
int error;
- assert(repo && name);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
if ((error = git_repository_head_for_worktree(&ref, repo, name)) < 0)
goto out;
@@ -2176,7 +2240,7 @@
git_reference *head;
int error;
- assert(head_out);
+ GIT_ASSERT_ARG(head_out);
if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2194,73 +2258,79 @@
int git_repository_head_for_worktree(git_reference **out, git_repository *repo, const char *name)
{
- git_buf path = GIT_BUF_INIT;
+ git_repository *worktree_repo = NULL;
+ git_worktree *worktree = NULL;
git_reference *head = NULL;
int error;
- assert(out && repo && name);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
*out = NULL;
- if ((error = get_worktree_file_path(&path, repo, name, GIT_HEAD_FILE)) < 0 ||
- (error = git_reference__read_head(&head, repo, path.ptr)) < 0)
+ 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) {
- git_reference *resolved;
-
- error = git_reference_lookup_resolved(&resolved, repo, git_reference_symbolic_target(head), -1);
- git_reference_free(head);
- head = resolved;
+ if ((error = git_reference_lookup_resolved(out, worktree_repo, git_reference_symbolic_target(head), -1)) < 0)
+ goto out;
+ } else {
+ *out = head;
+ head = NULL;
}
- *out = head;
-
out:
- if (error)
- git_reference_free(head);
-
- git_buf_dispose(&path);
-
+ git_reference_free(head);
+ git_worktree_free(worktree);
+ git_repository_free(worktree_repo);
return error;
}
-int git_repository_foreach_head(git_repository *repo,
- git_repository_foreach_head_cb cb,
- int flags, void *payload)
+int git_repository_foreach_worktree(git_repository *repo,
+ git_repository_foreach_worktree_cb cb,
+ void *payload)
{
- git_strarray worktrees = GIT_VECTOR_INIT;
- git_buf path = GIT_BUF_INIT;
- int error = 0;
+ git_strarray worktrees = {0};
+ git_repository *worktree_repo = NULL;
+ git_worktree *worktree = NULL;
+ int error;
size_t i;
+ if ((error = git_repository_open(&worktree_repo, repo->commondir)) < 0 ||
+ (error = cb(worktree_repo, payload) != 0))
+ goto out;
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO)) {
- /* Gather HEAD of main repository */
- if ((error = git_buf_joinpath(&path, repo->commondir, GIT_HEAD_FILE)) < 0 ||
- (error = cb(repo, path.ptr, payload) != 0))
- goto out;
- }
-
- if (!(flags & GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES)) {
- if ((error = git_worktree_list(&worktrees, repo)) < 0) {
- error = 0;
- goto out;
- }
+ git_repository_free(worktree_repo);
+ worktree_repo = NULL;
- /* Gather HEADs of all worktrees */
- for (i = 0; i < worktrees.count; i++) {
- if (get_worktree_file_path(&path, repo, worktrees.strings[i], GIT_HEAD_FILE) < 0)
- continue;
+ if ((error = git_worktree_list(&worktrees, repo)) < 0)
+ goto out;
- if ((error = cb(repo, path.ptr, payload)) != 0)
+ 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_buf_dispose(&path);
- git_strarray_free(&worktrees);
+ git_strarray_dispose(&worktrees);
+ git_repository_free(worktree_repo);
+ git_worktree_free(worktree);
return error;
}
@@ -2303,23 +2373,60 @@
return error;
}
+int git_repository_initialbranch(git_buf *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) {
+ branch = entry->value;
+ }
+ else if (error == GIT_ENOTFOUND) {
+ branch = GIT_BRANCH_DEFAULT;
+ }
+ else {
+ goto done;
+ }
+
+ if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
+ (error = git_buf_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 reference name");
+ error = -1;
+ }
+
+done:
+ git_config_entry_free(entry);
+ return error;
+}
+
int git_repository_is_empty(git_repository *repo)
{
git_reference *head = NULL;
- int is_empty = 0;
+ git_buf initialbranch = GIT_BUF_INIT;
+ int result = 0;
- if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0)
- return -1;
+ if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
+ (result = git_repository_initialbranch(&initialbranch, repo)) < 0)
+ goto done;
- if (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC)
- is_empty =
- (strcmp(git_reference_symbolic_target(head),
- GIT_REFS_HEADS_DIR "master") == 0) &&
- repo_contains_no_reference(repo);
+ 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_buf_dispose(&initialbranch);
- return is_empty;
+ return result;
}
static const char *resolved_parent_path(const git_repository *repo, git_repository_item_t item, git_repository_item_t fallback)
@@ -2372,13 +2479,13 @@
const char *git_repository_path(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
return repo->gitdir;
}
const char *git_repository_workdir(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
if (repo->is_bare)
return NULL;
@@ -2388,7 +2495,7 @@
const char *git_repository_commondir(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
return repo->commondir;
}
@@ -2398,7 +2505,8 @@
int error = 0;
git_buf path = GIT_BUF_INIT;
- assert(repo && workdir);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(workdir);
if (git_path_prettify_dir(&path, workdir, NULL) < 0)
return -1;
@@ -2438,13 +2546,13 @@
int git_repository_is_bare(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return repo->is_bare;
}
int git_repository_is_worktree(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return repo->is_worktree;
}
@@ -2453,7 +2561,7 @@
int error;
git_config *config;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if (repo->is_bare)
return 0;
@@ -2521,7 +2629,8 @@
struct stat st;
int error;
- git_buf_sanitize(out);
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
@@ -2566,7 +2675,10 @@
uint64_t len;
git_buf full_path = GIT_BUF_INIT;
- assert(out && path && repo); /* as_path can be NULL */
+ /* as_path can be NULL */
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(path);
+ GIT_ASSERT_ARG(repo);
/* At some point, it would be nice if repo could be NULL to just
* apply filter rules defined in system and global files, but for
@@ -2651,7 +2763,8 @@
git_object *object = NULL, *peeled = NULL;
git_reference *new_head = NULL, *current = NULL;
- assert(repo && id);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(id);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2687,7 +2800,8 @@
git_buf log_message = GIT_BUF_INIT;
int error;
- assert(repo && refname);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refname);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2739,7 +2853,8 @@
git_repository *repo,
const git_annotated_commit *commitish)
{
- assert(repo && commitish);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commitish);
return detach(repo, git_annotated_commit_id(commitish), commitish->description);
}
@@ -2751,7 +2866,7 @@
git_buf log_message = GIT_BUF_INIT;
int error;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2786,7 +2901,7 @@
git_buf repo_path = GIT_BUF_INIT;
int state = GIT_REPOSITORY_STATE_NONE;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if (git_buf_puts(&repo_path, repo->gitdir) < 0)
return -1;
@@ -2863,7 +2978,7 @@
int git_repository_state_cleanup(git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
}
@@ -2899,11 +3014,13 @@
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)
{
@@ -2927,8 +3044,8 @@
GIT_ERROR_CHECK_ALLOC(tmp_email);
}
- tmp_name = git__swap(repo->ident_name, tmp_name);
- tmp_email = git__swap(repo->ident_email, 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);
@@ -2938,28 +3055,16 @@
int git_repository_submodule_cache_all(git_repository *repo)
{
- int error;
-
- assert(repo);
-
- if ((error = git_strmap_new(&repo->submodule_cache)))
- return error;
-
- error = git_submodule__map(repo, repo->submodule_cache);
- return error;
+ GIT_ASSERT_ARG(repo);
+ return git_submodule_cache_init(&repo->submodule_cache, repo);
}
int git_repository_submodule_cache_clear(git_repository *repo)
{
- git_submodule *sm;
- assert(repo);
- if (repo->submodule_cache == NULL) {
- return 0;
- }
- git_strmap_foreach_value(repo->submodule_cache, sm, {
- git_submodule_free(sm);
- });
- git_strmap_free(repo->submodule_cache);
- repo->submodule_cache = 0;
- return 0;
+ int error = 0;
+ GIT_ASSERT_ARG(repo);
+
+ error = git_submodule_cache_free(repo->submodule_cache);
+ repo->submodule_cache = NULL;
+ return error;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/repository.h cargo-0.51.0/debian/libgit2/src/repository.h
--- cargo-0.47.0/debian/libgit2/src/repository.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/repository.h 2021-04-07 03:36:48.000000000 +0000
@@ -152,9 +152,9 @@
unsigned int lru_counter;
- git_atomic attr_session_key;
+ git_atomic32 attr_session_key;
- git_configmap_value configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
+ intptr_t configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
git_strmap *submodule_cache;
};
@@ -166,34 +166,11 @@
int git_repository_head_tree(git_tree **tree, git_repository *repo);
int git_repository_create_head(const char *git_dir, const char *ref_name);
-/*
- * Called for each HEAD.
- *
- * Can return either 0, causing the iteration over HEADs to
- * continue, or a non-0 value causing the iteration to abort. The
- * return value is passed back to the caller of
- * `git_repository_foreach_head`
- */
-typedef int (*git_repository_foreach_head_cb)(git_repository *repo, const char *path, void *payload);
+typedef int (*git_repository_foreach_worktree_cb)(git_repository *, void *);
-enum {
- /* Skip enumeration of the main repository HEAD */
- GIT_REPOSITORY_FOREACH_HEAD_SKIP_REPO = (1u << 0),
- /* Skip enumeration of worktree HEADs */
- GIT_REPOSITORY_FOREACH_HEAD_SKIP_WORKTREES = (1u << 1),
-};
-
-/*
- * Iterate over repository and all worktree HEADs.
- *
- * This function will be called for the repository HEAD and for
- * all HEADS of linked worktrees. For each HEAD, the callback is
- * executed with the given payload. The return value equals the
- * return value of the last executed callback function.
- */
-int git_repository_foreach_head(git_repository *repo,
- git_repository_foreach_head_cb cb,
- int flags, void *payload);
+int git_repository_foreach_worktree(git_repository *repo,
+ git_repository_foreach_worktree_cb cb,
+ void *payload);
/*
* Weak pointers to repository internals.
@@ -255,4 +232,10 @@
bool git_repository__reserved_names(
git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs);
+/*
+ * The default branch for the repository; the `init.defaultBranch`
+ * configuration option, if set, or `master` if it is not.
+ */
+int git_repository_initialbranch(git_buf *out, git_repository *repo);
+
#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/reset.c cargo-0.51.0/debian/libgit2/src/reset.c
--- cargo-0.47.0/debian/libgit2/src/reset.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/reset.c 2021-04-07 03:36:48.000000000 +0000
@@ -33,7 +33,7 @@
int error;
git_index *index = NULL;
- assert(pathspecs != NULL && pathspecs->count > 0);
+ GIT_ASSERT_ARG(pathspecs && pathspecs->count > 0);
memset(&entry, 0, sizeof(git_index_entry));
@@ -62,10 +62,10 @@
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);
- assert(delta->status == GIT_DELTA_ADDED ||
- delta->status == GIT_DELTA_MODIFIED ||
- delta->status == GIT_DELTA_CONFLICTED ||
- delta->status == GIT_DELTA_DELETED);
+ 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) {
@@ -113,7 +113,8 @@
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_buf log_message = GIT_BUF_INIT;
- assert(repo && target);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(target);
if (checkout_opts)
opts = *checkout_opts;
diff -Nru cargo-0.47.0/debian/libgit2/src/revert.c cargo-0.51.0/debian/libgit2/src/revert.c
--- cargo-0.47.0/debian/libgit2/src/revert.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/revert.c 2021-04-07 03:36:48.000000000 +0000
@@ -129,7 +129,10 @@
git_tree *parent_tree = NULL, *our_tree = NULL, *revert_tree = NULL;
int parent = 0, error = 0;
- assert(out && repo && revert_commit && our_commit);
+ 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)
@@ -180,7 +183,8 @@
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
int error;
- assert(repo && commit);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commit);
GIT_ERROR_CHECK_VERSION(given_opts, GIT_REVERT_OPTIONS_VERSION, "git_revert_options");
@@ -231,7 +235,9 @@
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 -Nru cargo-0.47.0/debian/libgit2/src/revparse.c cargo-0.51.0/debian/libgit2/src/revparse.c
--- cargo-0.47.0/debian/libgit2/src/revparse.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/revparse.c 2021-04-07 03:36:48.000000000 +0000
@@ -317,7 +317,7 @@
git_buf identifier = GIT_BUF_INIT;
git_time_t timestamp;
- assert(*out == NULL);
+ GIT_ASSERT(*out == NULL);
if (git_buf_put(&identifier, spec, identifier_len) < 0)
return -1;
@@ -524,7 +524,7 @@
{
git_buf_clear(buf);
- assert(spec[*pos] == '^' || spec[*pos] == '@');
+ GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '@');
(*pos)++;
@@ -537,7 +537,8 @@
if (spec[*pos] == '\0')
return GIT_EINVALIDSPEC;
- git_buf_putc(buf, spec[(*pos)++]);
+ if (git_buf_putc(buf, spec[(*pos)++]) < 0)
+ return -1;
}
(*pos)++;
@@ -549,7 +550,7 @@
{
git_buf_clear(buf);
- assert(spec[*pos] == ':');
+ GIT_ASSERT_ARG(spec[*pos] == ':');
(*pos)++;
@@ -567,7 +568,7 @@
int parsed, accumulated;
char kind = spec[*pos];
- assert(spec[*pos] == '^' || spec[*pos] == '~');
+ GIT_ASSERT_ARG(spec[*pos] == '^' || spec[*pos] == '~');
accumulated = 0;
@@ -585,7 +586,7 @@
*pos = end_ptr - spec;
}
- } while (spec[(*pos)] == kind && kind == '~');
+ } while (spec[(*pos)] == kind && kind == '~');
*n = accumulated;
@@ -659,7 +660,7 @@
return GIT_EINVALIDSPEC;
}
-int revparse__ext(
+static int revparse(
git_object **object_out,
git_reference **reference_out,
size_t *identifier_len_out,
@@ -675,7 +676,10 @@
bool should_return_reference = true;
- assert(object_out && reference_out && repo && spec);
+ GIT_ASSERT_ARG(object_out);
+ GIT_ASSERT_ARG(reference_out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(spec);
*object_out = NULL;
*reference_out = NULL;
@@ -835,7 +839,7 @@
git_object *obj = NULL;
git_reference *ref = NULL;
- if ((error = revparse__ext(&obj, &ref, &identifier_len, repo, spec)) < 0)
+ if ((error = revparse(&obj, &ref, &identifier_len, repo, spec)) < 0)
goto cleanup;
*object_out = obj;
@@ -881,7 +885,9 @@
const char *dotdot;
int error = 0;
- assert(revspec && repo && spec);
+ GIT_ASSERT_ARG(revspec);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(spec);
memset(revspec, 0x0, sizeof(*revspec));
diff -Nru cargo-0.47.0/debian/libgit2/src/revwalk.c cargo-0.51.0/debian/libgit2/src/revwalk.c
--- cargo-0.47.0/debian/libgit2/src/revwalk.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/revwalk.c 2021-04-07 03:36:48.000000000 +0000
@@ -99,7 +99,8 @@
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && oid);
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(oid);
return git_revwalk__push_commit(walk, oid, &opts);
}
@@ -108,7 +109,9 @@
int git_revwalk_hide(git_revwalk *walk, const git_oid *oid)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && oid);
+
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(oid);
opts.uninteresting = 1;
return git_revwalk__push_commit(walk, oid, &opts);
@@ -133,7 +136,8 @@
git_reference_iterator *iter;
size_t wildcard;
- assert(walk && glob);
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(glob);
if (given_opts)
memcpy(&opts, given_opts, sizeof(opts));
@@ -172,7 +176,9 @@
int git_revwalk_push_glob(git_revwalk *walk, const char *glob)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && glob);
+
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(glob);
return git_revwalk__push_glob(walk, glob, &opts);
}
@@ -180,7 +186,9 @@
int git_revwalk_hide_glob(git_revwalk *walk, const char *glob)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && glob);
+
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(glob);
opts.uninteresting = 1;
return git_revwalk__push_glob(walk, glob, &opts);
@@ -189,7 +197,8 @@
int git_revwalk_push_head(git_revwalk *walk)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk);
+
+ GIT_ASSERT_ARG(walk);
return git_revwalk__push_ref(walk, GIT_HEAD_FILE, &opts);
}
@@ -197,7 +206,8 @@
int git_revwalk_hide_head(git_revwalk *walk)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk);
+
+ GIT_ASSERT_ARG(walk);
opts.uninteresting = 1;
return git_revwalk__push_ref(walk, GIT_HEAD_FILE, &opts);
@@ -206,7 +216,9 @@
int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && refname);
+
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(refname);
return git_revwalk__push_ref(walk, refname, &opts);
}
@@ -249,7 +261,10 @@
int git_revwalk_hide_ref(git_revwalk *walk, const char *refname)
{
git_revwalk__push_options opts = GIT_REVWALK__PUSH_OPTIONS_INIT;
- assert(walk && refname);
+
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(refname);
+
opts.uninteresting = 1;
return git_revwalk__push_ref(walk, refname, &opts);
}
@@ -659,13 +674,11 @@
git_revwalk *walk = git__calloc(1, sizeof(git_revwalk));
GIT_ERROR_CHECK_ALLOC(walk);
- if (git_oidmap_new(&walk->commits) < 0)
+ if (git_oidmap_new(&walk->commits) < 0 ||
+ 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;
- if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0)
- return -1;
-
- git_pool_init(&walk->commit_pool, COMMIT_ALLOC);
walk->get_next = &revwalk_next_unsorted;
walk->enqueue = &revwalk_enqueue_unsorted;
@@ -696,13 +709,14 @@
git_repository *git_revwalk_repository(git_revwalk *walk)
{
- assert(walk);
+ GIT_ASSERT_ARG_WITH_RETVAL(walk, NULL);
+
return walk->repo;
}
int git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
{
- assert(walk);
+ GIT_ASSERT_ARG(walk);
if (walk->walking)
git_revwalk_reset(walk);
@@ -734,7 +748,8 @@
int error;
git_commit_list_node *next;
- assert(walk && oid);
+ GIT_ASSERT_ARG(walk);
+ GIT_ASSERT_ARG(oid);
if (!walk->walking) {
if ((error = prepare_walk(walk)) < 0)
@@ -759,7 +774,7 @@
{
git_commit_list_node *commit;
- assert(walk);
+ GIT_ASSERT_ARG(walk);
git_oidmap_foreach_value(walk->commits, commit, {
commit->seen = 0;
@@ -789,7 +804,7 @@
git_revwalk_hide_cb hide_cb,
void *payload)
{
- assert(walk);
+ GIT_ASSERT_ARG(walk);
if (walk->walking)
git_revwalk_reset(walk);
diff -Nru cargo-0.47.0/debian/libgit2/src/runtime.c cargo-0.51.0/debian/libgit2/src/runtime.c
--- cargo-0.47.0/debian/libgit2/src/runtime.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/runtime.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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 "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;
+
+ /* 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;
+
+ 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 -Nru cargo-0.47.0/debian/libgit2/src/runtime.h cargo-0.51.0/debian/libgit2/src/runtime.h
--- cargo-0.47.0/debian/libgit2/src/runtime.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/runtime.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 "common.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 oustanding 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 -Nru cargo-0.47.0/debian/libgit2/src/settings.c cargo-0.51.0/debian/libgit2/src/settings.c
--- cargo-0.47.0/debian/libgit2/src/settings.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/settings.c 1970-01-01 00:00:00.000000000 +0000
@@ -1,302 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * 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_OPENSSL
-# include
-#endif
-
-#ifdef GIT_MBEDTLS
-# include
-#endif
-
-#include
-#include "alloc.h"
-#include "sysdir.h"
-#include "cache.h"
-#include "global.h"
-#include "object.h"
-#include "odb.h"
-#include "refs.h"
-#include "index.h"
-#include "transports/smart.h"
-#include "transports/http.h"
-#include "streams/openssl.h"
-#include "streams/mbedtls.h"
-
-int git_libgit2_version(int *major, int *minor, int *rev)
-{
- *major = LIBGIT2_VER_MAJOR;
- *minor = LIBGIT2_VER_MINOR;
- *rev = LIBGIT2_VER_REVISION;
-
- return 0;
-}
-
-int git_libgit2_features(void)
-{
- return 0
-#ifdef GIT_THREADS
- | GIT_FEATURE_THREADS
-#endif
-#ifdef GIT_HTTPS
- | GIT_FEATURE_HTTPS
-#endif
-#if defined(GIT_SSH)
- | GIT_FEATURE_SSH
-#endif
-#if defined(GIT_USE_NSEC)
- | GIT_FEATURE_NSEC
-#endif
- ;
-}
-
-/* Declarations for tuneable settings */
-extern size_t git_mwindow__window_size;
-extern size_t git_mwindow__mapped_limit;
-extern size_t git_indexer__max_objects;
-extern bool git_disable_pack_keep_file_checks;
-
-static int config_level_to_sysdir(int config_level)
-{
- int val = -1;
-
- switch (config_level) {
- case GIT_CONFIG_LEVEL_SYSTEM:
- val = GIT_SYSDIR_SYSTEM;
- break;
- case GIT_CONFIG_LEVEL_XDG:
- val = GIT_SYSDIR_XDG;
- break;
- case GIT_CONFIG_LEVEL_GLOBAL:
- val = GIT_SYSDIR_GLOBAL;
- break;
- case GIT_CONFIG_LEVEL_PROGRAMDATA:
- val = GIT_SYSDIR_PROGRAMDATA;
- break;
- default:
- git_error_set(
- GIT_ERROR_INVALID, "invalid config path selector %d", config_level);
- }
-
- return val;
-}
-
-extern char *git__user_agent;
-extern char *git__ssl_ciphers;
-
-const char *git_libgit2__user_agent(void)
-{
- return git__user_agent;
-}
-
-const char *git_libgit2__ssl_ciphers(void)
-{
- return git__ssl_ciphers;
-}
-
-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_GET_SEARCH_PATH:
- if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) {
- git_buf *out = va_arg(ap, git_buf *);
- const git_buf *tmp;
-
- git_buf_sanitize(out);
- if ((error = git_sysdir_get(&tmp, error)) < 0)
- break;
-
- error = git_buf_sets(out, tmp->ptr);
- }
- break;
-
- case GIT_OPT_SET_SEARCH_PATH:
- if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0)
- error = git_sysdir_set(error, 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 *);
- const git_buf *tmp;
-
- git_buf_sanitize(out);
- if ((error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0)
- break;
-
- error = git_buf_sets(out, tmp->ptr);
- }
- 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 *);
- if (file)
- error = git_mbedtls__set_cert_location(file, 0);
- if (error && path)
- error = git_mbedtls__set_cert_location(path, 1);
- }
-#else
- git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations");
- error = -1;
-#endif
- break;
- case GIT_OPT_SET_USER_AGENT:
- git__free(git__user_agent);
- git__user_agent = git__strdup(va_arg(ap, const char *));
- if (!git__user_agent) {
- git_error_set_oom();
- error = -1;
- }
-
- 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_GET_USER_AGENT:
- {
- git_buf *out = va_arg(ap, git_buf *);
- git_buf_sanitize(out);
- error = git_buf_sets(out, git__user_agent);
- }
- 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_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;
-
- default:
- git_error_set(GIT_ERROR_INVALID, "invalid option key");
- error = -1;
- }
-
- va_end(ap);
-
- return error;
-}
diff -Nru cargo-0.47.0/debian/libgit2/src/settings.h cargo-0.51.0/debian/libgit2/src/settings.h
--- cargo-0.47.0/debian/libgit2/src/settings.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/settings.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,11 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+extern int git_settings_global_init(void);
+
+extern const char *git_libgit2__user_agent(void);
+extern const char *git_libgit2__ssl_ciphers(void);
diff -Nru cargo-0.47.0/debian/libgit2/src/signature.c cargo-0.51.0/debian/libgit2/src/signature.c
--- cargo-0.47.0/debian/libgit2/src/signature.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/signature.c 2021-04-07 03:36:48.000000000 +0000
@@ -65,7 +65,8 @@
{
git_signature *p = NULL;
- assert(name && email);
+ GIT_ASSERT_ARG(name);
+ GIT_ASSERT_ARG(email);
*sig_out = NULL;
@@ -279,7 +280,8 @@
const char *buf_end;
int error;
- assert(out && buf);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(buf);
*out = NULL;
@@ -302,8 +304,6 @@
int offset, hours, mins;
char sign;
- assert(buf && sig);
-
offset = sig->when.offset;
sign = (sig->when.offset < 0 || sig->when.sign == '-') ? '-' : '+';
@@ -320,7 +320,8 @@
bool git_signature__equal(const git_signature *one, const git_signature *two)
{
- assert(one && two);
+ GIT_ASSERT_ARG(one);
+ GIT_ASSERT_ARG(two);
return
git__strcmp(one->name, two->name) == 0 &&
diff -Nru cargo-0.47.0/debian/libgit2/src/sortedcache.c cargo-0.51.0/debian/libgit2/src/sortedcache.c
--- cargo-0.47.0/debian/libgit2/src/sortedcache.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/sortedcache.c 2021-04-07 03:36:48.000000000 +0000
@@ -25,9 +25,8 @@
sc = git__calloc(1, alloclen);
GIT_ERROR_CHECK_ALLOC(sc);
- git_pool_init(&sc->pool, 1);
-
- if (git_vector_init(&sc->items, 4, item_cmp) < 0 ||
+ if (git_pool_init(&sc->pool, 1) < 0 ||
+ git_vector_init(&sc->items, 4, item_cmp) < 0 ||
git_strmap_new(&sc->map) < 0)
goto fail;
diff -Nru cargo-0.47.0/debian/libgit2/src/sortedcache.h cargo-0.51.0/debian/libgit2/src/sortedcache.h
--- cargo-0.47.0/debian/libgit2/src/sortedcache.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/sortedcache.h 2021-04-07 03:36:48.000000000 +0000
@@ -12,7 +12,7 @@
#include "util.h"
#include "futils.h"
#include "vector.h"
-#include "thread-utils.h"
+#include "thread.h"
#include "pool.h"
#include "strmap.h"
diff -Nru cargo-0.47.0/debian/libgit2/src/stash.c cargo-0.51.0/debian/libgit2/src/stash.c
--- cargo-0.47.0/debian/libgit2/src/stash.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/stash.c 2021-04-07 03:36:48.000000000 +0000
@@ -173,7 +173,7 @@
git_index *index,
const char *path)
{
- git_index *repo_index;
+ git_index *repo_index = NULL;
git_index_entry entry = {{0}};
struct stat st;
int error;
@@ -187,7 +187,7 @@
return error;
git_index_entry__init_from_stat(&entry, &st,
- (repo_index != NULL || !repo_index->distrust_filemode));
+ (repo_index == NULL || !repo_index->distrust_filemode));
entry.path = path;
@@ -546,7 +546,9 @@
git_buf msg = GIT_BUF_INIT;
int error;
- assert(out && repo && stasher);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(stasher);
if ((error = git_repository__ensure_not_bare(repo, "stash save")) < 0)
return error;
@@ -776,10 +778,12 @@
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 { \
diff -Nru cargo-0.47.0/debian/libgit2/src/status.c cargo-0.51.0/debian/libgit2/src/status.c
--- cargo-0.47.0/debian/libgit2/src/status.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/status.c 2021-04-07 03:36:48.000000000 +0000
@@ -391,14 +391,14 @@
size_t git_status_list_entrycount(git_status_list *status)
{
- assert(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)
{
- assert(status);
+ GIT_ASSERT_ARG_WITH_RETVAL(status, NULL);
return git_vector_get(&status->paired, i);
}
@@ -492,7 +492,9 @@
struct status_file_info sfi = {0};
git_index *index;
- assert(status_flags && repo && path);
+ GIT_ASSERT_ARG(status_flags);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(path);
if ((error = git_repository_index__weakptr(&index, repo)) < 0)
return error;
@@ -548,15 +550,18 @@
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)
{
- assert(out);
+ GIT_ASSERT_ARG(out);
+
GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
out->stat_calls = 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/strarray.c cargo-0.51.0/debian/libgit2/src/strarray.c
--- cargo-0.47.0/debian/libgit2/src/strarray.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/strarray.c 2021-04-07 03:36:48.000000000 +0000
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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"
+
+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 -Nru cargo-0.47.0/debian/libgit2/src/streams/mbedtls.c cargo-0.51.0/debian/libgit2/src/streams/mbedtls.c
--- cargo-0.47.0/debian/libgit2/src/streams/mbedtls.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/mbedtls.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,7 +11,7 @@
#include
-#include "global.h"
+#include "runtime.h"
#include "stream.h"
#include "streams/socket.h"
#include "netops.h"
@@ -152,9 +152,7 @@
if (!loaded && crtpath != NULL && stat(crtpath, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
loaded = (git_mbedtls__set_cert_location(crtpath, 1) == 0);
- git__on_shutdown(shutdown_ssl);
-
- return 0;
+ return git_runtime_shutdown_register(shutdown_ssl);
cleanup:
mbedtls_ctr_drbg_free(ctr_drbg);
@@ -183,8 +181,8 @@
char errbuf[512];
int ret = -1;
- assert(error != MBEDTLS_ERR_SSL_WANT_READ);
- assert(error != MBEDTLS_ERR_SSL_WANT_WRITE);
+ GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_READ);
+ GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_WRITE);
if (error != 0)
mbedtls_strerror( error, errbuf, 512 );
@@ -425,7 +423,9 @@
git_stream *stream;
int error;
- assert(out && host && port);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(host);
+ GIT_ASSERT_ARG(port);
if ((error = git_socket_stream_new(&stream, host, port)) < 0)
return error;
@@ -444,7 +444,7 @@
char errbuf[512];
mbedtls_x509_crt *cacert;
- assert(path != NULL);
+ GIT_ASSERT_ARG(path);
cacert = git__malloc(sizeof(mbedtls_x509_crt));
GIT_ERROR_CHECK_ALLOC(cacert);
diff -Nru cargo-0.47.0/debian/libgit2/src/streams/openssl.c cargo-0.51.0/debian/libgit2/src/streams/openssl.c
--- cargo-0.47.0/debian/libgit2/src/streams/openssl.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/openssl.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,7 +11,8 @@
#include
-#include "global.h"
+#include "runtime.h"
+#include "settings.h"
#include "posix.h"
#include "stream.h"
#include "streams/socket.h"
@@ -285,9 +286,7 @@
if (init_bio_method() < 0)
goto error;
- git__on_shutdown(shutdown_ssl);
-
- return 0;
+ return git_runtime_shutdown_register(shutdown_ssl);
error:
git_error_set(GIT_ERROR_NET, "could not initialize openssl: %s",
@@ -324,8 +323,8 @@
}
CRYPTO_set_locking_callback(openssl_locking_function);
- git__on_shutdown(shutdown_ssl_locking);
- return 0;
+ return git_runtime_shutdown_register(shutdown_ssl_locking);
+
#elif !defined(OPENSSL_LEGACY_API)
return 0;
#else
@@ -415,8 +414,8 @@
err = SSL_get_error(ssl, error);
- assert(err != SSL_ERROR_WANT_READ);
- assert(err != SSL_ERROR_WANT_WRITE);
+ GIT_ASSERT(err != SSL_ERROR_WANT_READ);
+ GIT_ASSERT(err != SSL_ERROR_WANT_WRITE);
switch (err) {
case SSL_ERROR_WANT_CONNECT:
@@ -655,15 +654,16 @@
static int openssl_certificate(git_cert **out, git_stream *stream)
{
openssl_stream *st = (openssl_stream *) stream;
- int len;
X509 *cert = SSL_get_peer_certificate(st->ssl);
- unsigned char *guard, *encoded_cert;
+ 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");
- return -1;
+ error = -1;
+ goto out;
}
encoded_cert = git__malloc(len);
@@ -673,18 +673,23 @@
len = i2d_X509(cert, &guard);
if (len < 0) {
- git__free(encoded_cert);
git_error_set(GIT_ERROR_NET, "failed to retrieve certificate information");
- return -1;
+ 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;
- return 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)
@@ -752,7 +757,9 @@
{
openssl_stream *st;
- assert(out && in && host);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(in);
+ GIT_ASSERT_ARG(host);
st = git__calloc(1, sizeof(openssl_stream));
GIT_ERROR_CHECK_ALLOC(st);
@@ -795,7 +802,9 @@
git_stream *stream = NULL;
int error;
- assert(out && host && port);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(host);
+ GIT_ASSERT_ARG(port);
if ((error = git_socket_stream_new(&stream, host, port)) < 0)
return error;
diff -Nru cargo-0.47.0/debian/libgit2/src/streams/registry.c cargo-0.51.0/debian/libgit2/src/streams/registry.c
--- cargo-0.47.0/debian/libgit2/src/streams/registry.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/registry.c 2021-04-07 03:36:48.000000000 +0000
@@ -5,10 +5,11 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "git2/errors.h"
-
#include "common.h"
-#include "global.h"
+
+#include "streams/registry.h"
+
+#include "runtime.h"
#include "streams/tls.h"
#include "streams/mbedtls.h"
#include "streams/openssl.h"
@@ -32,8 +33,7 @@
if (git_rwlock_init(&stream_registry.lock) < 0)
return -1;
- git__on_shutdown(shutdown_stream_registry);
- return 0;
+ return git_runtime_shutdown_register(shutdown_stream_registry);
}
GIT_INLINE(void) stream_registration_cpy(
@@ -51,7 +51,7 @@
git_stream_registration *target;
int error = GIT_ENOTFOUND;
- assert(out);
+ GIT_ASSERT_ARG(out);
switch(type) {
case GIT_STREAM_STANDARD:
@@ -61,7 +61,7 @@
target = &stream_registry.tls_callbacks;
break;
default:
- assert(0);
+ git_error_set(GIT_ERROR_INVALID, "invalid stream type");
return -1;
}
@@ -81,7 +81,7 @@
int git_stream_register(git_stream_t type, git_stream_registration *registration)
{
- assert(!registration || registration->init);
+ GIT_ASSERT(!registration || registration->init);
GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
@@ -100,7 +100,7 @@
return 0;
}
-
+#ifndef GIT_DEPRECATE_HARD
int git_stream_register_tls(
int GIT_CALLBACK(ctor)(git_stream **out, const char *host, const char *port))
{
@@ -116,3 +116,4 @@
return git_stream_register(GIT_STREAM_TLS, NULL);
}
}
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/streams/socket.c cargo-0.51.0/debian/libgit2/src/streams/socket.c
--- cargo-0.47.0/debian/libgit2/src/streams/socket.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/socket.c 2021-04-07 03:36:48.000000000 +0000
@@ -183,7 +183,9 @@
{
git_socket_stream *st;
- assert(out && host && port);
+ 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);
@@ -217,7 +219,9 @@
git_stream_registration custom = {0};
int error;
- assert(out && host && port);
+ 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;
diff -Nru cargo-0.47.0/debian/libgit2/src/streams/stransport.c cargo-0.51.0/debian/libgit2/src/streams/stransport.c
--- cargo-0.47.0/debian/libgit2/src/streams/stransport.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/stransport.c 2021-04-07 03:36:48.000000000 +0000
@@ -167,7 +167,7 @@
if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
return stransport_error(ret);
- assert(processed < SSIZE_MAX);
+ GIT_ASSERT(processed < SSIZE_MAX);
return (ssize_t)processed;
}
@@ -251,7 +251,9 @@
stransport_stream *st;
OSStatus ret;
- assert(out && in && host);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(in);
+ GIT_ASSERT_ARG(host);
st = git__calloc(1, sizeof(stransport_stream));
GIT_ERROR_CHECK_ALLOC(st);
@@ -305,7 +307,8 @@
git_stream *stream = NULL;
int error;
- assert(out && host);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(host);
error = git_socket_stream_new(&stream, host, port);
diff -Nru cargo-0.47.0/debian/libgit2/src/streams/tls.c cargo-0.51.0/debian/libgit2/src/streams/tls.c
--- cargo-0.47.0/debian/libgit2/src/streams/tls.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/streams/tls.c 2021-04-07 03:36:48.000000000 +0000
@@ -8,7 +8,6 @@
#include "git2/errors.h"
#include "common.h"
-#include "global.h"
#include "streams/registry.h"
#include "streams/tls.h"
#include "streams/mbedtls.h"
@@ -21,7 +20,9 @@
git_stream_registration custom = {0};
int error;
- assert(out && host && port);
+ 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;
@@ -50,7 +51,8 @@
int (*wrap)(git_stream **, git_stream *, const char *) = NULL;
git_stream_registration custom = {0};
- assert(out && in);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(in);
if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
wrap = custom.wrap;
diff -Nru cargo-0.47.0/debian/libgit2/src/submodule.c cargo-0.51.0/debian/libgit2/src/submodule.c
--- cargo-0.47.0/debian/libgit2/src/submodule.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/submodule.c 2021-04-07 03:36:48.000000000 +0000
@@ -249,24 +249,62 @@
return error;
}
+int git_submodule_cache_init(git_strmap **out, git_repository *repo)
+{
+ int error = 0;
+ git_strmap *cache = NULL;
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ if ((error = git_strmap_new(&cache)) < 0)
+ return error;
+ if ((error = git_submodule__map(repo, cache)) < 0) {
+ git_submodule_cache_free(cache);
+ return error;
+ }
+ *out = cache;
+ return error;
+}
+
+int git_submodule_cache_free(git_strmap *cache)
+{
+ git_submodule *sm = NULL;
+ if (cache == NULL)
+ return 0;
+ git_strmap_foreach_value(cache, sm, {
+ git_submodule_free(sm);
+ });
+ git_strmap_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_strmap *cache)
+{
int error;
unsigned int location;
git_submodule *sm;
- assert(repo && name);
+ 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 (repo->submodule_cache != NULL) {
- if ((sm = git_strmap_get(repo->submodule_cache, name)) != NULL) {
+ if (cache != NULL) {
+ if ((sm = git_strmap_get(cache, name)) != NULL) {
if (out) {
*out = sm;
GIT_REFCOUNT_INC(*out);
@@ -520,7 +558,8 @@
git_submodule *sm;
git_config *mods = NULL;
- assert(repo && map);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(map);
/* get sources that we will need to check */
if (git_repository_index(&idx, repo) < 0)
@@ -698,7 +737,9 @@
git_repository *subrepo = NULL;
bool path_occupied;
- assert(repo && url && path);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(url);
+ GIT_ASSERT_ARG(path);
/* see if there is already an entry for this submodule */
@@ -799,7 +840,8 @@
git_config *cfg = NULL;
git_buf buf = GIT_BUF_INIT;
- assert(out && sm);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(sm);
/* get the configured remote url of the submodule */
if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
@@ -840,7 +882,7 @@
git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
- assert(submodule);
+ GIT_ASSERT_ARG(submodule);
if (given_opts)
memcpy(&sub_opts, given_opts, sizeof(sub_opts));
@@ -879,7 +921,7 @@
int error;
git_index *index;
- assert(sm);
+ GIT_ASSERT_ARG(sm);
if ((error = git_repository_index__weakptr(&index, sm->repo)) < 0 ||
(error = git_index_add_bypath(index, GIT_MODULES_FILE)) < 0)
@@ -898,7 +940,7 @@
git_index_entry entry;
struct stat st;
- assert(sm);
+ GIT_ASSERT_ARG(sm);
/* force reload of wd OID by git_submodule_open */
sm->flags = sm->flags & ~GIT_SUBMODULE_STATUS__WD_OID_VALID;
@@ -958,7 +1000,7 @@
return error;
}
-const char *git_submodule_update_to_str(git_submodule_update_t update)
+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)
@@ -969,25 +1011,25 @@
git_repository *git_submodule_owner(git_submodule *submodule)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
return submodule->repo;
}
const char *git_submodule_name(git_submodule *submodule)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
return submodule->name;
}
const char *git_submodule_path(git_submodule *submodule)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
return submodule->path;
}
const char *git_submodule_url(git_submodule *submodule)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
return submodule->url;
}
@@ -996,9 +1038,12 @@
int error = 0;
git_buf normalized = GIT_BUF_INIT;
- assert(out && repo && url);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(url);
- git_buf_sanitize(out);
+ if ((error = git_buf_sanitize(out)) < 0)
+ return error;
/* We do this in all platforms in case someone on Windows created the .gitmodules */
if (strchr(url, '\\')) {
@@ -1066,28 +1111,30 @@
const char *git_submodule_branch(git_submodule *submodule)
{
- assert(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)
{
-
- assert(repo && name);
+ 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)
{
- assert(repo && name && 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)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
if (submodule->flags & GIT_SUBMODULE_STATUS__INDEX_OID_VALID)
return &submodule->index_oid;
@@ -1097,7 +1144,7 @@
const git_oid *git_submodule_head_id(git_submodule *submodule)
{
- assert(submodule);
+ GIT_ASSERT_ARG_WITH_RETVAL(submodule, NULL);
if (submodule->flags & GIT_SUBMODULE_STATUS__HEAD_OID_VALID)
return &submodule->head_oid;
@@ -1107,7 +1154,7 @@
const git_oid *git_submodule_wd_id(git_submodule *submodule)
{
- assert(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)) {
@@ -1128,28 +1175,32 @@
git_submodule_ignore_t git_submodule_ignore(git_submodule *submodule)
{
- assert(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)
{
- assert(repo && name);
+ 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)
{
- assert(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)
{
- assert(repo && name);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
return write_mapped_var(repo, name, _sm_update_map, ARRAY_SIZE(_sm_update_map), "update", update);
}
@@ -1157,13 +1208,14 @@
git_submodule_recurse_t git_submodule_fetch_recurse_submodules(
git_submodule *submodule)
{
- assert(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)
{
- assert(repo && name);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
return write_mapped_var(repo, name, _sm_recurse_map, ARRAY_SIZE(_sm_recurse_map), "fetchRecurseSubmodules", recurse);
}
@@ -1240,10 +1292,12 @@
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)
{
@@ -1258,7 +1312,7 @@
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
- assert(sm);
+ GIT_ASSERT_ARG(sm);
if (_update_options)
memcpy(&update_options, _update_options, sizeof(git_submodule_update_options));
@@ -1401,7 +1455,7 @@
/* write "submodule.NAME.update" if not default */
val = (sm->update == GIT_SUBMODULE_UPDATE_CHECKOUT) ?
- NULL : git_submodule_update_to_str(sm->update);
+ NULL : submodule_update_to_str(sm->update);
if ((error = git_buf_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
(error = git_config__update_entry(
@@ -1471,7 +1525,8 @@
unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH;
const char *wd;
- assert(sm && subrepo);
+ GIT_ASSERT_ARG(sm);
+ GIT_ASSERT_ARG(subrepo);
if (git_repository__ensure_not_bare(
sm->repo, "open submodule repository") < 0)
@@ -1607,7 +1662,7 @@
GIT_UNUSED(force);
- assert(sm);
+ GIT_ASSERT_ARG(sm);
if ((error = git_submodule_name_is_valid(sm->repo, sm->name, 0)) <= 0)
/* This should come with a warning, but we've no API for that */
@@ -1724,7 +1779,9 @@
git_submodule *sm;
int error;
- assert(status && repo && name);
+ GIT_ASSERT_ARG(status);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
if ((error = git_submodule_lookup(&sm, repo, name)) < 0)
return error;
@@ -1737,7 +1794,8 @@
int git_submodule_location(unsigned int *location, git_submodule *sm)
{
- assert(location && sm);
+ GIT_ASSERT_ARG(location);
+ GIT_ASSERT_ARG(sm);
return git_submodule__status(
location, NULL, NULL, NULL, sm, GIT_SUBMODULE_IGNORE_ALL);
@@ -1838,7 +1896,7 @@
return 0;
}
-int git_submodule_parse_recurse(git_submodule_recurse_t *out, const char *value)
+static int submodule_parse_recurse(git_submodule_recurse_t *out, const char *value)
{
int val;
@@ -1934,7 +1992,7 @@
if ((error = get_value(&value, cfg, &key, sm->name, "fetchRecurseSubmodules")) == 0) {
in_config = 1;
- if ((error = git_submodule_parse_recurse(&sm->fetch_recurse, value)) < 0)
+ if ((error = submodule_parse_recurse(&sm->fetch_recurse, value)) < 0)
goto cleanup;
sm->fetch_recurse_default = sm->fetch_recurse;
} else if (error != GIT_ENOTFOUND) {
diff -Nru cargo-0.47.0/debian/libgit2/src/submodule.h cargo-0.51.0/debian/libgit2/src/submodule.h
--- cargo-0.47.0/debian/libgit2/src/submodule.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/submodule.h 2021-04-07 03:36:48.000000000 +0000
@@ -101,12 +101,6 @@
git_oid wd_oid;
};
-/* Force revalidation of submodule data cache (alloc as needed) */
-extern int git_submodule_cache_refresh(git_repository *repo);
-
-/* Release all submodules */
-extern void git_submodule_cache_free(git_repository *repo);
-
/* Additional flags on top of public GIT_SUBMODULE_STATUS values */
enum {
GIT_SUBMODULE_STATUS__WD_SCANNED = (1u << 20),
@@ -122,9 +116,15 @@
#define GIT_SUBMODULE_STATUS__CLEAR_INTERNAL(S) \
((S) & ~(0xFFFFFFFFu << 20))
-/* Internal lookup does not attempt to refresh cached data */
-extern int git_submodule__lookup(
- git_submodule **out, git_repository *repo, const char *path);
+/* Initialize an external submodule cache for the provided repo. */
+extern int git_submodule_cache_init(git_strmap **out, git_repository *repo);
+
+/* Release the resources of the submodule cache. */
+extern int git_submodule_cache_free(git_strmap *cache);
+
+/* Submodule lookup with an explicit cache */
+extern int git_submodule__lookup_with_cache(
+ git_submodule **out, git_repository *repo, const char *path, git_strmap *cache);
/* Internal status fn returns status and optionally the various OIDs */
extern int git_submodule__status(
diff -Nru cargo-0.47.0/debian/libgit2/src/sysdir.c cargo-0.51.0/debian/libgit2/src/sysdir.c
--- cargo-0.47.0/debian/libgit2/src/sysdir.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/sysdir.c 2021-04-07 03:36:48.000000000 +0000
@@ -7,7 +7,7 @@
#include "sysdir.h"
-#include "global.h"
+#include "runtime.h"
#include "buffer.h"
#include "path.h"
#include
@@ -45,7 +45,7 @@
long buflen;
int error;
- assert(out);
+ GIT_ASSERT_ARG(out);
if ((buflen = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1)
buflen = 1024;
@@ -189,9 +189,7 @@
for (i = 0; !error && i < ARRAY_SIZE(git_sysdir__dirs); i++)
error = git_sysdir__dirs[i].guess(&git_sysdir__dirs[i].buf);
- git__on_shutdown(git_sysdir_global_shutdown);
-
- return error;
+ return git_runtime_shutdown_register(git_sysdir_global_shutdown);
}
static int git_sysdir_check_selector(git_sysdir_t which)
@@ -206,7 +204,7 @@
int git_sysdir_get(const git_buf **out, git_sysdir_t which)
{
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
@@ -216,25 +214,6 @@
return 0;
}
-int git_sysdir_get_str(
- char *out,
- size_t outlen,
- git_sysdir_t which)
-{
- const git_buf *path = NULL;
-
- GIT_ERROR_CHECK_ERROR(git_sysdir_check_selector(which));
- GIT_ERROR_CHECK_ERROR(git_sysdir_get(&path, which));
-
- if (!out || path->size >= outlen) {
- git_error_set(GIT_ERROR_NOMEMORY, "buffer is too short for the path");
- return GIT_EBUFS;
- }
-
- git_buf_copy_cstr(out, outlen, path);
- return 0;
-}
-
#define PATH_MAGIC "$PATH"
int git_sysdir_set(git_sysdir_t which, const char *search_path)
@@ -317,8 +296,11 @@
}
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_buf_dispose(path);
- git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name);
return GIT_ENOTFOUND;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/sysdir.h cargo-0.51.0/debian/libgit2/src/sysdir.h
--- cargo-0.47.0/debian/libgit2/src/sysdir.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/sysdir.h 2021-04-07 03:36:48.000000000 +0000
@@ -94,17 +94,6 @@
extern int git_sysdir_get(const git_buf **out, git_sysdir_t which);
/**
- * Get search path into a preallocated buffer
- *
- * @param out String buffer to write into
- * @param outlen Size of string buffer
- * @param which Which search path to return
- * @return 0 on success, GIT_EBUFS if out is too small, <0 on other failure
- */
-
-extern int git_sysdir_get_str(char *out, size_t outlen, 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
diff -Nru cargo-0.47.0/debian/libgit2/src/tag.c cargo-0.51.0/debian/libgit2/src/tag.c
--- cargo-0.47.0/debian/libgit2/src/tag.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/tag.c 2021-04-07 03:36:48.000000000 +0000
@@ -27,25 +27,25 @@
int git_tag_target(git_object **target, const git_tag *t)
{
- assert(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)
{
- assert(t);
+ GIT_ASSERT_ARG_WITH_RETVAL(t, NULL);
return &t->target;
}
git_object_t git_tag_target_type(const git_tag *t)
{
- assert(t);
+ GIT_ASSERT_ARG_WITH_RETVAL(t, GIT_OBJECT_INVALID);
return t->type;
}
const char *git_tag_name(const git_tag *t)
{
- assert(t);
+ GIT_ASSERT_ARG_WITH_RETVAL(t, NULL);
return t->tag_name;
}
@@ -56,7 +56,7 @@
const char *git_tag_message(const git_tag *t)
{
- assert(t);
+ GIT_ASSERT_ARG_WITH_RETVAL(t, NULL);
return t->message;
}
@@ -259,8 +259,10 @@
int error;
- assert(repo && tag_name && target);
- assert(!create_tag_annotation || (tagger && message));
+ 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");
@@ -313,7 +315,12 @@
const git_signature *tagger,
const char *message)
{
- assert(oid && repo && tag_name && target && tagger && 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);
}
@@ -339,7 +346,8 @@
git_reference *new_ref = NULL;
git_buf ref_name = GIT_BUF_INIT;
- assert(oid && buffer);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(buffer);
memset(&tag, 0, sizeof(tag));
@@ -454,7 +462,8 @@
{
tag_cb_data data;
- assert(repo && cb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(cb);
data.cb = cb;
data.cb_data = cb_data;
@@ -493,7 +502,9 @@
tag_filter_data filter;
git_vector taglist;
- assert(tag_names && repo && pattern);
+ GIT_ASSERT_ARG(tag_names);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(pattern);
if ((error = git_vector_init(&taglist, 8, NULL)) < 0)
return error;
@@ -522,9 +533,36 @@
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_buf ref_name = GIT_BUF_INIT;
+ int error = 0;
+
+ GIT_ASSERT(valid);
+
+ /*
+ * Discourage tag name starting with dash,
+ * https://github.com/git/git/commit/4f0accd638b8d2
+ */
+ if (!name || name[0] == '-')
+ goto done;
+
+ if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 ||
+ (error = git_buf_puts(&ref_name, name)) < 0)
+ goto done;
+
+ error = git_reference_name_is_valid(valid, ref_name.ptr);
+
+done:
+ git_buf_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 -Nru cargo-0.47.0/debian/libgit2/src/thread.c cargo-0.51.0/debian/libgit2/src/thread.c
--- cargo-0.47.0/debian/libgit2/src/thread.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/thread.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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"
+
+#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 -Nru cargo-0.47.0/debian/libgit2/src/thread.h cargo-0.51.0/debian/libgit2/src/thread.h
--- cargo-0.47.0/debian/libgit2/src/thread.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/thread.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,422 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 -DTHREADSAFE=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 -DTHREADSAFE=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
+
+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
+}
+
+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
+}
+
+GIT_INLINE(int) git_atomic32_add(git_atomic32 *a, int32_t addend)
+{
+#if defined(GIT_WIN32)
+ return InterlockedExchangeAdd(&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
+}
+
+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
+}
+
+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)
+ volatile void *foundval;
+ foundval = InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval);
+ return (foundval == oldval) ? oldval : newval;
+#elif defined(GIT_BUILTIN_ATOMIC)
+ bool success = __atomic_compare_exchange(ptr, &oldval, &newval, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+ return success ? oldval : newval;
+#elif defined(GIT_BUILTIN_SYNC)
+ volatile void *foundval;
+ foundval = __sync_val_compare_and_swap(ptr, oldval, newval);
+ return (foundval == oldval) ? 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 * volatile foundval;
+ __atomic_exchange(ptr, &newval, &foundval, __ATOMIC_SEQ_CST);
+ return foundval;
+#elif defined(GIT_BUILTIN_SYNC)
+ return __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;
+ volatile void *foundval = NULL;
+ foundval = InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval);
+ return foundval;
+#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
+
+GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
+{
+#if defined(GIT_WIN32)
+ return InterlockedExchangeAdd64(&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
+}
+
+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
+}
+
+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(thread, start_routine, arg) git__noop()
+#define git_thread_join(id, status) git__noop()
+
+/* Pthreads Mutex */
+#define git_mutex unsigned int
+#define git_mutex_init(a) git__noop()
+#define git_mutex_init(a) git__noop()
+#define git_mutex_lock(a) git__noop()
+#define git_mutex_unlock(a) git__noop()
+#define git_mutex_free(a) git__noop()
+
+/* Pthreads condition vars */
+#define git_cond unsigned int
+#define git_cond_init(c) git__noop()
+#define git_cond_free(c) git__noop()
+#define git_cond_wait(c, l) git__noop()
+#define git_cond_signal(c) git__noop()
+#define git_cond_broadcast(c) git__noop()
+
+/* Pthreads rwlock */
+#define git_rwlock unsigned int
+#define git_rwlock_init(a) git__noop()
+#define git_rwlock_rdlock(a) git__noop()
+#define git_rwlock_rdunlock(a) git__noop()
+#define git_rwlock_wrlock(a) git__noop()
+#define git_rwlock_wrunlock(a) git__noop()
+#define git_rwlock_free(a) git__noop()
+#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)
+{
+ if (*ptr == oldval)
+ *ptr = newval;
+ else
+ oldval = newval;
+ return oldval;
+}
+
+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 oldval with newval
+ * @return oldval if it was replaced or newval if it was not
+ */
+#define git_atomic_compare_and_swap(P,O,N) \
+ git_atomic__compare_and_swap((void * volatile *)P, O, N)
+
+#define git_atomic_swap(ptr, val) \
+ (void *)git_atomic__swap((void * volatile *)&ptr, val)
+
+#define git_atomic_load(ptr) \
+ (void *)git_atomic__load((void * volatile *)&ptr)
+
+#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 -Nru cargo-0.47.0/debian/libgit2/src/threadstate.c cargo-0.51.0/debian/libgit2/src/threadstate.c
--- cargo-0.47.0/debian/libgit2/src/threadstate.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/threadstate.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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 "threadstate.h"
+#include "runtime.h"
+
+/**
+ * Handle the thread-local state
+ *
+ * `git_threadstate_global_init` will be called as part
+ * of `git_libgit2_init` (which itself must be called
+ * before calling any other function in the library).
+ *
+ * This function allocates a TLS index to store the per-
+ * thread state.
+ *
+ * Any internal method that requires thread-local state
+ * will then call `git_threadstate_get()` which returns a
+ * pointer to the thread-local state structure; this
+ * structure is lazily allocated on each thread.
+ *
+ * This mechanism will register a shutdown handler
+ * (`git_threadstate_global_shutdown`) which will free the
+ * TLS index. This shutdown handler will be called by
+ * `git_libgit2_shutdown`.
+ */
+
+static git_tlsdata_key tls_key;
+
+static void threadstate_dispose(git_threadstate *threadstate)
+{
+ if (!threadstate)
+ return;
+
+ git__free(threadstate->error_t.message);
+ threadstate->error_t.message = NULL;
+}
+
+static void GIT_SYSTEM_CALL threadstate_free(void *threadstate)
+{
+ threadstate_dispose(threadstate);
+ git__free(threadstate);
+}
+
+static void git_threadstate_global_shutdown(void)
+{
+ git_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_threadstate_global_init(void)
+{
+ if (git_tlsdata_init(&tls_key, &threadstate_free) != 0)
+ return -1;
+
+ return git_runtime_shutdown_register(git_threadstate_global_shutdown);
+}
+
+git_threadstate *git_threadstate_get(void)
+{
+ git_threadstate *threadstate;
+
+ if ((threadstate = git_tlsdata_get(tls_key)) != NULL)
+ return threadstate;
+
+ if ((threadstate = git__calloc(1, sizeof(git_threadstate))) == NULL ||
+ git_buf_init(&threadstate->error_buf, 0) < 0)
+ return NULL;
+
+ git_tlsdata_set(tls_key, threadstate);
+ return threadstate;
+}
diff -Nru cargo-0.47.0/debian/libgit2/src/threadstate.h cargo-0.51.0/debian/libgit2/src/threadstate.h
--- cargo-0.47.0/debian/libgit2/src/threadstate.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/threadstate.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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_threadstate_h__
+#define INCLUDE_threadstate_h__
+
+#include "common.h"
+
+typedef struct {
+ git_error *last_error;
+ git_error error_t;
+ git_buf error_buf;
+ char oid_fmt[GIT_OID_HEXSZ+1];
+} git_threadstate;
+
+extern int git_threadstate_global_init(void);
+extern git_threadstate *git_threadstate_get(void);
+
+#define GIT_THREADSTATE (git_threadstate_get())
+
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/thread-utils.c cargo-0.51.0/debian/libgit2/src/thread-utils.c
--- cargo-0.47.0/debian/libgit2/src/thread-utils.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/thread-utils.c 1970-01-01 00:00:00.000000000 +0000
@@ -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.
- */
-
-#include "common.h"
-#include "thread-utils.h"
-
-#ifdef _WIN32
-#ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-# include
-#elif defined(hpux) || defined(__hpux) || defined(_hpux)
-# include
-#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 -Nru cargo-0.47.0/debian/libgit2/src/thread-utils.h cargo-0.51.0/debian/libgit2/src/thread-utils.h
--- cargo-0.47.0/debian/libgit2/src/thread-utils.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/thread-utils.h 1970-01-01 00:00:00.000000000 +0000
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This 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_utils_h__
-#define INCLUDE_thread_utils_h__
-
-#if defined(__GNUC__) && defined(GIT_THREADS)
-# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1))
-# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF
-# endif
-#endif
-
-/* Common operations even if threading has been disabled */
-typedef struct {
-#if defined(GIT_WIN32)
- volatile long val;
-#else
- volatile int val;
-#endif
-} git_atomic;
-
-#ifdef GIT_ARCH_64
-
-typedef struct {
-#if defined(GIT_WIN32)
- __int64 val;
-#else
- int64_t val;
-#endif
-} git_atomic64;
-
-typedef git_atomic64 git_atomic_ssize;
-
-#define git_atomic_ssize_add git_atomic64_add
-
-#else
-
-typedef git_atomic git_atomic_ssize;
-
-#define git_atomic_ssize_add git_atomic_add
-
-#endif
-
-#ifdef GIT_THREADS
-
-#ifdef GIT_WIN32
-# include "win32/thread.h"
-#else
-# include "unix/pthread.h"
-#endif
-
-GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
-{
-#if defined(GIT_WIN32)
- InterlockedExchange(&a->val, (LONG)val);
-#elif defined(__GNUC__)
- __sync_lock_test_and_set(&a->val, val);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
-}
-
-GIT_INLINE(int) git_atomic_inc(git_atomic *a)
-{
-#if defined(GIT_WIN32)
- return InterlockedIncrement(&a->val);
-#elif defined(__GNUC__)
- return __sync_add_and_fetch(&a->val, 1);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
-}
-
-GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
-{
-#if defined(GIT_WIN32)
- return InterlockedExchangeAdd(&a->val, addend);
-#elif defined(__GNUC__)
- return __sync_add_and_fetch(&a->val, addend);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
-}
-
-GIT_INLINE(int) git_atomic_dec(git_atomic *a)
-{
-#if defined(GIT_WIN32)
- return InterlockedDecrement(&a->val);
-#elif defined(__GNUC__)
- return __sync_sub_and_fetch(&a->val, 1);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
-}
-
-GIT_INLINE(void *) git___compare_and_swap(
- void * volatile *ptr, void *oldval, void *newval)
-{
- volatile void *foundval;
-#if defined(GIT_WIN32)
- foundval = InterlockedCompareExchangePointer((volatile PVOID *)ptr, newval, oldval);
-#elif defined(__GNUC__)
- foundval = __sync_val_compare_and_swap(ptr, oldval, newval);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
- return (foundval == oldval) ? oldval : newval;
-}
-
-GIT_INLINE(volatile void *) git___swap(
- void * volatile *ptr, void *newval)
-{
-#if defined(GIT_WIN32)
- return InterlockedExchangePointer(ptr, newval);
-#else
- return __sync_lock_test_and_set(ptr, newval);
-#endif
-}
-
-#ifdef GIT_ARCH_64
-
-GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
-{
-#if defined(GIT_WIN32)
- return InterlockedExchangeAdd64(&a->val, addend);
-#elif defined(__GNUC__)
- return __sync_add_and_fetch(&a->val, addend);
-#else
-# error "Unsupported architecture for atomic operations"
-#endif
-}
-
-#endif
-
-#else
-
-#define git_thread unsigned int
-#define git_thread_create(thread, start_routine, arg) 0
-#define git_thread_join(id, status) (void)0
-
-/* Pthreads Mutex */
-#define git_mutex unsigned int
-GIT_INLINE(int) git_mutex_init(git_mutex *mutex) \
- { GIT_UNUSED(mutex); return 0; }
-GIT_INLINE(int) git_mutex_lock(git_mutex *mutex) \
- { GIT_UNUSED(mutex); return 0; }
-#define git_mutex_unlock(a) (void)0
-#define git_mutex_free(a) (void)0
-
-/* Pthreads condition vars */
-#define git_cond unsigned int
-#define git_cond_init(c, a) (void)0
-#define git_cond_free(c) (void)0
-#define git_cond_wait(c, l) (void)0
-#define git_cond_signal(c) (void)0
-#define git_cond_broadcast(c) (void)0
-
-/* Pthreads rwlock */
-#define git_rwlock unsigned int
-#define git_rwlock_init(a) 0
-#define git_rwlock_rdlock(a) 0
-#define git_rwlock_rdunlock(a) (void)0
-#define git_rwlock_wrlock(a) 0
-#define git_rwlock_wrunlock(a) (void)0
-#define git_rwlock_free(a) (void)0
-#define GIT_RWLOCK_STATIC_INIT 0
-
-
-GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
-{
- a->val = val;
-}
-
-GIT_INLINE(int) git_atomic_inc(git_atomic *a)
-{
- return ++a->val;
-}
-
-GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
-{
- a->val += addend;
- return a->val;
-}
-
-GIT_INLINE(int) git_atomic_dec(git_atomic *a)
-{
- return --a->val;
-}
-
-GIT_INLINE(void *) git___compare_and_swap(
- void * volatile *ptr, void *oldval, void *newval)
-{
- if (*ptr == oldval)
- *ptr = newval;
- else
- oldval = newval;
- return oldval;
-}
-
-GIT_INLINE(volatile void *) git___swap(
- void * volatile *ptr, void *newval)
-{
- volatile void *old = *ptr;
- *ptr = newval;
- return old;
-}
-
-#ifdef GIT_ARCH_64
-
-GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
-{
- a->val += addend;
- return a->val;
-}
-
-#endif
-
-#endif
-
-GIT_INLINE(int) git_atomic_get(git_atomic *a)
-{
- return (int)a->val;
-}
-
-/* Atomically replace oldval with newval
- * @return oldval if it was replaced or newval if it was not
- */
-#define git__compare_and_swap(P,O,N) \
- git___compare_and_swap((void * volatile *)P, O, N)
-
-#define git__swap(ptr, val) (void *)git___swap((void * volatile *)&ptr, val)
-
-extern int git_online_cpus(void);
-
-#if defined(GIT_THREADS) && defined(_MSC_VER)
-# define GIT_MEMORY_BARRIER MemoryBarrier()
-#elif defined(GIT_THREADS)
-# define GIT_MEMORY_BARRIER __sync_synchronize()
-#else
-# define GIT_MEMORY_BARRIER /* noop */
-#endif
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/trace.c cargo-0.51.0/debian/libgit2/src/trace.c
--- cargo-0.47.0/debian/libgit2/src/trace.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/trace.c 2021-04-07 03:36:48.000000000 +0000
@@ -8,7 +8,7 @@
#include "trace.h"
#include "buffer.h"
-#include "global.h"
+#include "runtime.h"
#include "git2/trace.h"
#ifdef GIT_TRACE
@@ -20,7 +20,7 @@
int git_trace_set(git_trace_level_t level, git_trace_cb callback)
{
#ifdef GIT_TRACE
- assert(level == 0 || callback != NULL);
+ GIT_ASSERT_ARG(level == 0 || callback != NULL);
git_trace__data.level = level;
git_trace__data.callback = callback;
diff -Nru cargo-0.47.0/debian/libgit2/src/transaction.c cargo-0.51.0/debian/libgit2/src/transaction.c
--- cargo-0.47.0/debian/libgit2/src/transaction.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transaction.c 2021-04-07 03:36:48.000000000 +0000
@@ -57,7 +57,9 @@
int git_transaction_config_new(git_transaction **out, git_config *cfg)
{
git_transaction *tx;
- assert(out && cfg);
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(cfg);
tx = git__calloc(1, sizeof(git_transaction));
GIT_ERROR_CHECK_ALLOC(tx);
@@ -74,9 +76,11 @@
git_pool pool;
git_transaction *tx = NULL;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
- git_pool_init(&pool, 1);
+ if ((error = git_pool_init(&pool, 1)) < 0)
+ goto on_error;
tx = git_pool_mallocz(&pool, sizeof(git_transaction));
if (!tx) {
@@ -108,7 +112,8 @@
int error;
transaction_node *node;
- assert(tx && refname);
+ GIT_ASSERT_ARG(tx);
+ GIT_ASSERT_ARG(refname);
node = git_pool_mallocz(&tx->pool, sizeof(transaction_node));
GIT_ERROR_CHECK_ALLOC(node);
@@ -175,7 +180,9 @@
int error;
transaction_node *node;
- assert(tx && refname && target);
+ GIT_ASSERT_ARG(tx);
+ GIT_ASSERT_ARG(refname);
+ GIT_ASSERT_ARG(target);
if ((error = find_locked(&node, tx, refname)) < 0)
return error;
@@ -194,7 +201,9 @@
int error;
transaction_node *node;
- assert(tx && refname && target);
+ GIT_ASSERT_ARG(tx);
+ GIT_ASSERT_ARG(refname);
+ GIT_ASSERT_ARG(target);
if ((error = find_locked(&node, tx, refname)) < 0)
return error;
@@ -271,7 +280,9 @@
int error;
transaction_node *node;
- assert(tx && refname && reflog);
+ GIT_ASSERT_ARG(tx);
+ GIT_ASSERT_ARG(refname);
+ GIT_ASSERT_ARG(reflog);
if ((error = find_locked(&node, tx, refname)) < 0)
return error;
@@ -319,7 +330,7 @@
transaction_node *node;
int error = 0;
- assert(tx);
+ GIT_ASSERT_ARG(tx);
if (tx->type == TRANSACTION_CONFIG) {
error = git_config_unlock(tx->cfg, true);
@@ -354,7 +365,8 @@
transaction_node *node;
git_pool pool;
- assert(tx);
+ if (!tx)
+ return;
if (tx->type == TRANSACTION_CONFIG) {
if (tx->cfg) {
diff -Nru cargo-0.47.0/debian/libgit2/src/transport.c cargo-0.51.0/debian/libgit2/src/transport.c
--- cargo-0.47.0/debian/libgit2/src/transport.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transport.c 2021-04-07 03:36:48.000000000 +0000
@@ -148,8 +148,8 @@
size_t i;
int error = 0;
- assert(scheme);
- assert(cb);
+ GIT_ASSERT_ARG(scheme);
+ GIT_ASSERT_ARG(cb);
if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
goto on_error;
@@ -186,7 +186,7 @@
size_t i;
int error = 0;
- assert(scheme);
+ GIT_ASSERT_ARG(scheme);
if ((error = git_buf_printf(&prefix, "%s://", scheme)) < 0)
goto done;
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/auth_negotiate.c cargo-0.51.0/debian/libgit2/src/transports/auth_negotiate.c
--- cargo-0.47.0/debian/libgit2/src/transports/auth_negotiate.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/auth_negotiate.c 2021-04-07 03:36:48.000000000 +0000
@@ -65,7 +65,9 @@
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
- assert(ctx && ctx->configured && challenge);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(challenge);
+ GIT_ASSERT(ctx->configured);
git__free(ctx->challenge);
@@ -108,7 +110,12 @@
size_t challenge_len;
int error = 0;
- assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDENTIAL_DEFAULT);
+ 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;
@@ -202,7 +209,7 @@
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
return (ctx->complete == 1);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/auth_ntlm.c cargo-0.51.0/debian/libgit2/src/transports/auth_ntlm.c
--- cargo-0.47.0/debian/libgit2/src/transports/auth_ntlm.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/auth_ntlm.c 2021-04-07 03:36:48.000000000 +0000
@@ -29,7 +29,8 @@
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- assert(ctx && challenge);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(challenge);
git__free(ctx->challenge);
@@ -46,7 +47,7 @@
char *domain = NULL, *domainuser = NULL;
int error = 0;
- assert(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
+ GIT_ASSERT(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
cred = (git_credential_userpass_plaintext *)_cred;
if ((sep = strchr(cred->username, '\\')) != NULL) {
@@ -86,7 +87,10 @@
size_t challenge_len, msg_len;
int error = -1;
- assert(buf && ctx && ctx->ntlm);
+ GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(ctx);
+
+ GIT_ASSERT(ctx->ntlm);
challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0;
@@ -162,7 +166,7 @@
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
return (ctx->complete == true);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/credential.c cargo-0.51.0/debian/libgit2/src/transports/credential.c
--- cargo-0.47.0/debian/libgit2/src/transports/credential.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/credential.c 2021-04-07 03:36:48.000000000 +0000
@@ -85,7 +85,9 @@
{
git_credential_userpass_plaintext *c;
- assert(cred && username && password);
+ 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);
@@ -233,7 +235,9 @@
{
git_credential_ssh_key *c;
- assert(username && cred && privatekey);
+ 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);
@@ -269,7 +273,9 @@
{
git_credential_ssh_interactive *c;
- assert(out && username && prompt_callback);
+ 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);
@@ -290,7 +296,8 @@
int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) {
git_credential_ssh_key *c;
- assert(username && cred);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_ssh_key));
GIT_ERROR_CHECK_ALLOC(c);
@@ -317,7 +324,8 @@
{
git_credential_ssh_custom *c;
- assert(username && cred);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_ssh_custom));
GIT_ERROR_CHECK_ALLOC(c);
@@ -347,7 +355,7 @@
{
git_credential_default *c;
- assert(cred);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_default));
GIT_ERROR_CHECK_ALLOC(c);
@@ -364,7 +372,7 @@
git_credential_username *c;
size_t len, allocsize;
- assert(cred);
+ GIT_ASSERT_ARG(cred);
len = strlen(username);
@@ -391,6 +399,7 @@
/* Deprecated credential functions */
+#ifndef GIT_DEPRECATE_HARD
int git_cred_has_username(git_credential *cred)
{
return git_credential_has_username(cred);
@@ -474,3 +483,4 @@
{
git_credential_free(cred);
}
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/credential_helpers.c cargo-0.51.0/debian/libgit2/src/transports/credential_helpers.c
--- cargo-0.47.0/debian/libgit2/src/transports/credential_helpers.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/credential_helpers.c 2021-04-07 03:36:48.000000000 +0000
@@ -54,6 +54,7 @@
/* Deprecated credential functions */
+#ifndef GIT_DEPRECATE_HARD
int git_cred_userpass(
git_credential **out,
const char *url,
@@ -64,3 +65,4 @@
return git_credential_userpass(out, url, user_from_url,
allowed_types, payload);
}
+#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/git.c cargo-0.51.0/debian/libgit2/src/transports/git.c
--- cargo-0.47.0/debian/libgit2/src/transports/git.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/git.c 2021-04-07 03:36:48.000000000 +0000
@@ -327,7 +327,7 @@
{
git_subtransport *t = (git_subtransport *) subtransport;
- assert(!t->current_stream);
+ GIT_ASSERT(!t->current_stream);
GIT_UNUSED(t);
@@ -338,8 +338,6 @@
{
git_subtransport *t = (git_subtransport *) subtransport;
- assert(!t->current_stream);
-
git__free(t);
}
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/http.c cargo-0.51.0/debian/libgit2/src/transports/http.c
--- cargo-0.47.0/debian/libgit2/src/transports/http.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/http.c 2021-04-07 03:36:48.000000000 +0000
@@ -14,7 +14,6 @@
#include "buffer.h"
#include "net.h"
#include "netops.h"
-#include "global.h"
#include "remote.h"
#include "git2/sys/credential.h"
#include "smart.h"
@@ -417,7 +416,7 @@
goto done;
}
- assert (stream->state == HTTP_STATE_RECEIVING_RESPONSE);
+ GIT_ASSERT(stream->state == HTTP_STATE_RECEIVING_RESPONSE);
error = git_http_client_read_body(transport->http_client, buffer, buffer_size);
@@ -555,7 +554,7 @@
goto done;
}
- assert(stream->state == HTTP_STATE_SENDING_REQUEST);
+ GIT_ASSERT(stream->state == HTTP_STATE_SENDING_REQUEST);
error = git_http_client_send_body(transport->http_client, buffer, len);
@@ -589,7 +588,7 @@
(error = handle_response(&complete, stream, &response, false)) < 0)
goto done;
- assert(complete);
+ GIT_ASSERT(complete);
stream->state = HTTP_STATE_RECEIVING_RESPONSE;
}
@@ -638,7 +637,8 @@
const http_service *service;
int error;
- assert(out && t);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(t);
*out = NULL;
@@ -721,7 +721,7 @@
GIT_UNUSED(param);
- assert(out);
+ GIT_ASSERT_ARG(out);
transport = git__calloc(sizeof(http_subtransport), 1);
GIT_ERROR_CHECK_ALLOC(transport);
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/httpclient.c cargo-0.51.0/debian/libgit2/src/transports/httpclient.c
--- cargo-0.47.0/debian/libgit2/src/transports/httpclient.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/httpclient.c 2021-04-07 03:36:48.000000000 +0000
@@ -10,7 +10,6 @@
#include "http_parser.h"
#include "vector.h"
#include "trace.h"
-#include "global.h"
#include "httpclient.h"
#include "http.h"
#include "auth.h"
@@ -146,7 +145,8 @@
void git_http_response_dispose(git_http_response *response)
{
- assert(response);
+ if (!response)
+ return;
git__free(response->content_type);
git__free(response->location);
@@ -400,7 +400,7 @@
return 0;
}
- assert(ctx->output_size >= ctx->output_written);
+ 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);
@@ -445,7 +445,7 @@
0);
}
-const char *name_for_method(git_http_method method)
+static const char *name_for_method(git_http_method method)
{
switch (method) {
case GIT_HTTP_METHOD_GET:
@@ -666,7 +666,8 @@
size_t i;
int error;
- assert(client && request);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT_ARG(request);
git_buf_clear(&client->request_msg);
buf = &client->request_msg;
@@ -843,7 +844,10 @@
{
int ret, diff = 0;
- assert(client && request && request->url);
+ 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;
@@ -923,7 +927,7 @@
(error = git_http_client_skip_body(client)) < 0)
goto done;
- assert(client->state == DONE);
+ GIT_ASSERT(client->state == DONE);
if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
save_early_response(client, &response);
@@ -1038,6 +1042,7 @@
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;
@@ -1054,6 +1059,9 @@
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;
@@ -1116,11 +1124,6 @@
return -1;
}
- if (parser->upgrade) {
- git_error_set(GIT_ERROR_HTTP, "server requested upgrade");
- return -1;
- }
-
if (ctx->parse_status == PARSE_STATUS_ERROR) {
client->connected = 0;
return ctx->error ? ctx->error : -1;
@@ -1139,7 +1142,7 @@
* final byte when paused in a callback. Consume that byte.
* https://github.com/nodejs/http-parser/issues/97
*/
- assert(client->read_buf.size > parsed_len);
+ GIT_ASSERT(client->read_buf.size > parsed_len);
http_parser_pause(parser, 0);
@@ -1191,7 +1194,7 @@
/* If we're not keeping alive, don't bother. */
if (!client->keepalive) {
client->connected = 0;
- return;
+ goto done;
}
parser_context.client = client;
@@ -1205,6 +1208,9 @@
git_error_clear();
client->connected = 0;
}
+
+done:
+ git_buf_clear(&client->read_buf);
}
int git_http_client_send_request(
@@ -1214,7 +1220,8 @@
git_http_response response = {0};
int error = -1;
- assert(client && request);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT_ARG(request);
/* If the client did not finish reading, clean up the stream. */
if (client->state == READING_BODY)
@@ -1285,7 +1292,7 @@
git_buf hdr = GIT_BUF_INIT;
int error;
- assert(client);
+ GIT_ASSERT_ARG(client);
/* If we're waiting for proxy auth, don't sending more requests. */
if (client->state == HAS_EARLY_RESPONSE)
@@ -1302,7 +1309,7 @@
server = &client->server;
if (client->request_body_len) {
- assert(buffer_len <= client->request_body_remain);
+ GIT_ASSERT(buffer_len <= client->request_body_remain);
if ((error = stream_write(server, buffer, buffer_len)) < 0)
goto done;
@@ -1325,7 +1332,8 @@
{
int error = 0;
- assert(client && client->state == SENDING_BODY);
+ 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");
@@ -1345,7 +1353,8 @@
http_parser_context parser_context = {0};
int error;
- assert(response && client);
+ GIT_ASSERT_ARG(response);
+ GIT_ASSERT_ARG(client);
if (client->state == SENDING_BODY) {
if ((error = complete_request(client)) < 0)
@@ -1367,8 +1376,11 @@
git_http_response_dispose(response);
- git_vector_free_deep(&client->server.auth_challenges);
- git_vector_free_deep(&client->proxy.auth_challenges);
+ if (client->current_server == PROXY) {
+ git_vector_free_deep(&client->proxy.auth_challenges);
+ } else if(client->current_server == SERVER) {
+ git_vector_free_deep(&client->server.auth_challenges);
+ }
client->state = READING_RESPONSE;
client->keepalive = 0;
@@ -1382,7 +1394,7 @@
goto done;
}
- assert(client->state == READING_BODY || client->state == DONE);
+ GIT_ASSERT(client->state == READING_BODY || client->state == DONE);
done:
git_buf_dispose(&parser_context.parse_header_name);
@@ -1419,18 +1431,23 @@
client->parser.data = &parser_context;
/*
- * Clients expect to get a non-zero amount of data from us.
- * With a sufficiently small buffer, one might only read a chunk
- * length. Loop until we actually have data to return.
+ * 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;
}
- assert(parser_context.output_written <= INT_MAX);
+ GIT_ASSERT(parser_context.output_written <= INT_MAX);
error = (int)parser_context.output_written;
done:
@@ -1484,7 +1501,7 @@
{
git_http_client *client;
- assert(out);
+ GIT_ASSERT_ARG(out);
client = git__calloc(1, sizeof(git_http_client));
GIT_ERROR_CHECK_ALLOC(client);
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/http.h cargo-0.51.0/debian/libgit2/src/transports/http.h
--- cargo-0.47.0/debian/libgit2/src/transports/http.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/http.h 2021-04-07 03:36:48.000000000 +0000
@@ -9,6 +9,7 @@
#define INCLUDE_transports_http_h__
#include "buffer.h"
+#include "settings.h"
#include "httpclient.h"
#define GIT_HTTP_REPLAY_MAX 15
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/local.c cargo-0.51.0/debian/libgit2/src/transports/local.c
--- cargo-0.47.0/debian/libgit2/src/transports/local.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/local.c 2021-04-07 03:36:48.000000000 +0000
@@ -36,7 +36,7 @@
char *url;
int direction;
int flags;
- git_atomic cancelled;
+ git_atomic32 cancelled;
git_repository *repo;
git_transport_message_cb progress_cb;
git_transport_message_cb error_cb;
@@ -158,7 +158,7 @@
git_remote_head *head;
git_strarray ref_names = {0};
- assert(t);
+ GIT_ASSERT_ARG(t);
if (git_reference_list(&ref_names, t->repo) < 0)
goto on_error;
@@ -185,12 +185,12 @@
}
t->have_refs = 1;
- git_strarray_free(&ref_names);
+ git_strarray_dispose(&ref_names);
return 0;
on_error:
git_vector_free(&t->refs);
- git_strarray_free(&ref_names);
+ git_strarray_dispose(&ref_names);
return -1;
}
@@ -671,7 +671,7 @@
{
transport_local *t = (transport_local *)transport;
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
static int local_close(git_transport *transport)
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/smart.c cargo-0.51.0/debian/libgit2/src/transports/smart.c
--- cargo-0.47.0/debian/libgit2/src/transports/smart.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/smart.c 2021-04-07 03:36:48.000000000 +0000
@@ -18,7 +18,7 @@
size_t old_len, bytes_read;
int error;
- assert(t->current_stream);
+ GIT_ASSERT(t->current_stream);
old_len = buf->offset;
@@ -30,7 +30,7 @@
if (t->packetsize_cb && !t->cancelled.val) {
error = t->packetsize_cb(bytes_read, t->packetsize_payload);
if (error) {
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
return GIT_EUSER;
}
}
@@ -132,7 +132,7 @@
size_t i;
if (t->custom_headers.count)
- git_strarray_free(&t->custom_headers);
+ git_strarray_dispose(&t->custom_headers);
if (!custom_headers)
return 0;
@@ -346,7 +346,7 @@
return error;
/* If this is a stateful implementation, the stream we get back should be the same */
- assert(t->rpc || t->current_stream == stream);
+ 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;
@@ -375,7 +375,7 @@
return error;
/* If this is a stateful implementation, the stream we get back should be the same */
- assert(t->rpc || t->current_stream == *stream);
+ 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;
@@ -389,7 +389,7 @@
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
static int git_smart__is_connected(git_transport *transport)
@@ -465,7 +465,7 @@
git_vector_free(refs);
git__free((char *)t->proxy.url);
- git_strarray_free(&t->custom_headers);
+ git_strarray_dispose(&t->custom_headers);
git__free(t);
}
@@ -481,7 +481,9 @@
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- assert(transport && cert && hostname);
+ GIT_ASSERT_ARG(transport);
+ GIT_ASSERT_ARG(cert);
+ GIT_ASSERT_ARG(hostname);
if (!t->certificate_check_cb)
return GIT_PASSTHROUGH;
@@ -493,7 +495,8 @@
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- assert(out && transport);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(transport);
if (!t->cred_acquire_cb)
return GIT_PASSTHROUGH;
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/smart.h cargo-0.51.0/debian/libgit2/src/transports/smart.h
--- cargo-0.47.0/debian/libgit2/src/transports/smart.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/smart.h 2021-04-07 03:36:48.000000000 +0000
@@ -153,7 +153,7 @@
git_vector refs;
git_vector heads;
git_vector common;
- git_atomic cancelled;
+ git_atomic32 cancelled;
packetsize_cb packetsize_cb;
void *packetsize_payload;
unsigned rpc : 1,
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/smart_protocol.c cargo-0.51.0/debian/libgit2/src/transports/smart_protocol.c
--- cargo-0.47.0/debian/libgit2/src/transports/smart_protocol.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/smart_protocol.c 2021-04-07 03:36:48.000000000 +0000
@@ -64,7 +64,9 @@
continue;
}
- gitno_consume(buf, line_end);
+ if (gitno_consume(buf, line_end) < 0)
+ return -1;
+
if (pkt->type == GIT_PKT_ERR) {
git_error_set(GIT_ERROR_NET, "remote error: %s", ((git_pkt_err *)pkt)->error);
git__free(pkt);
@@ -236,7 +238,9 @@
}
} while (error);
- gitno_consume(buf, line_end);
+ if (gitno_consume(buf, line_end) < 0)
+ return -1;
+
if (out_type != NULL)
*out_type = pkt->type;
if (out_pkt != NULL)
@@ -531,7 +535,7 @@
/* We might have something in the buffer already from negotiate_fetch */
if (t->buffer.offset > 0 && !t->cancelled.val)
if (t->packetsize_cb(t->buffer.offset, t->packetsize_payload))
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
@@ -791,7 +795,8 @@
continue;
}
- gitno_consume(buf, line_end);
+ if (gitno_consume(buf, line_end) < 0)
+ return -1;
error = 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/ssh.c cargo-0.51.0/debian/libgit2/src/transports/ssh.c
--- cargo-0.47.0/debian/libgit2/src/transports/ssh.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/ssh.c 2021-04-07 03:36:48.000000000 +0000
@@ -11,7 +11,7 @@
#include
#endif
-#include "global.h"
+#include "runtime.h"
#include "git2.h"
#include "buffer.h"
#include "net.h"
@@ -238,7 +238,7 @@
{
ssh_stream *s;
- assert(stream);
+ GIT_ASSERT_ARG(stream);
s = git__calloc(sizeof(ssh_stream), 1);
GIT_ERROR_CHECK_ALLOC(s);
@@ -404,8 +404,8 @@
case GIT_CREDENTIAL_SSH_MEMORY: {
git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
- assert(c->username);
- assert(c->privatekey);
+ GIT_ASSERT(c->username);
+ GIT_ASSERT(c->privatekey);
rc = libssh2_userauth_publickey_frommemory(
session,
@@ -483,7 +483,7 @@
LIBSSH2_SESSION* s;
git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
- assert(session);
+ GIT_ASSERT_ARG(session);
s = libssh2_session_init();
if (!s) {
@@ -563,9 +563,28 @@
if (t->owner->certificate_check_cb != NULL) {
git_cert_hostkey cert = {{ 0 }}, *cert_ptr;
const char *key;
+ size_t cert_len;
+ int cert_type;
cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
+ key = libssh2_session_hostkey(session, &cert_len, &cert_type);
+ 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;
+ 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) {
@@ -772,7 +791,7 @@
{
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
- assert(!t->current_stream);
+ GIT_ASSERT(!t->current_stream);
GIT_UNUSED(t);
@@ -783,8 +802,6 @@
{
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
- assert(!t->current_stream);
-
git__free(t->cmd_uploadpack);
git__free(t->cmd_receivepack);
git__free(t);
@@ -849,7 +866,7 @@
#ifdef GIT_SSH
ssh_subtransport *t;
- assert(out);
+ GIT_ASSERT_ARG(out);
GIT_UNUSED(param);
@@ -867,7 +884,7 @@
GIT_UNUSED(owner);
GIT_UNUSED(param);
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
@@ -911,7 +928,7 @@
GIT_UNUSED(owner);
GIT_UNUSED(payload);
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
@@ -934,8 +951,7 @@
return -1;
}
- git__on_shutdown(shutdown_ssh);
- return 0;
+ return git_runtime_shutdown_register(shutdown_ssh);
#else
diff -Nru cargo-0.47.0/debian/libgit2/src/transports/winhttp.c cargo-0.51.0/debian/libgit2/src/transports/winhttp.c
--- cargo-0.47.0/debian/libgit2/src/transports/winhttp.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/transports/winhttp.c 2021-04-07 03:36:48.000000000 +0000
@@ -17,7 +17,6 @@
#include "smart.h"
#include "remote.h"
#include "repository.h"
-#include "global.h"
#include "http.h"
#include "git2/sys/credential.h"
@@ -41,14 +40,18 @@
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
#endif
-#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_1
+#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200
#endif
-#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_2
+#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 HTTP_STATUS_PERMANENT_REDIRECT
# define HTTP_STATUS_PERMANENT_REDIRECT 308
#endif
@@ -743,7 +746,8 @@
DWORD protocols =
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
- WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
+ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 |
+ WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3;
t->session = NULL;
t->connection = NULL;
@@ -788,14 +792,20 @@
}
/*
- * Do a best-effort attempt to enable TLS 1.2 but allow this to
- * fail; if TLS 1.2 support is not available for some reason,
+ * 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).
*/
- WinHttpSetOption(t->session,
+ if (WinHttpSetOption(t->session,
WINHTTP_OPTION_SECURE_PROTOCOLS,
&protocols,
- sizeof(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");
@@ -864,42 +874,65 @@
static int send_request(winhttp_stream *s, size_t len, bool chunked)
{
- int request_failed = 0, cert_valid = 1, error = 0;
- DWORD ignore_flags;
+ int request_failed = 1, error, attempts = 0;
+ DWORD ignore_flags, send_request_error;
git_error_clear();
- if ((error = do_send_request(s, len, chunked)) < 0) {
- if (GetLastError() != ERROR_WINHTTP_SECURE_FAILURE) {
- git_error_set(GIT_ERROR_OS, "failed to send request");
- return -1;
- }
-
- request_failed = 1;
- cert_valid = 0;
- }
- git_error_clear();
- if ((error = certificate_check(s, cert_valid)) < 0) {
- if (!git_error_last())
- git_error_set(GIT_ERROR_OS, "user cancelled certificate check");
+ 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;
+ }
+ }
- return error;
- }
+ if (!request_failed || !cert_valid) {
+ git_error_clear();
+ if ((error = certificate_check(s, cert_valid)) < 0) {
+ if (!git_error_last())
+ git_error_set(GIT_ERROR_OS, "user cancelled certificate check");
- /* if neither the request nor the certificate check returned errors, we're done */
- if (!request_failed)
- return 0;
+ return error;
+ }
+ }
- ignore_flags = no_check_cert_flags;
+ /* 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 (!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;
+ }
+ }
}
- if ((error = do_send_request(s, len, chunked)) < 0)
- git_error_set(GIT_ERROR_OS, "failed to send request with unchecked certificate");
-
return error;
}
@@ -993,7 +1026,7 @@
}
if (s->chunked) {
- assert(s->verb == post_verb);
+ GIT_ASSERT(s->verb == post_verb);
/* Flush, if necessary */
if (s->chunk_buffer_len > 0 &&
@@ -1044,7 +1077,7 @@
}
len -= bytes_read;
- assert(bytes_read == bytes_written);
+ GIT_ASSERT(bytes_read == bytes_written);
}
git__free(buffer);
@@ -1156,7 +1189,7 @@
if (error < 0) {
return error;
} else if (!error) {
- assert(t->server.cred);
+ GIT_ASSERT(t->server.cred);
winhttp_stream_close(s);
goto replay;
}
@@ -1170,7 +1203,7 @@
if (error < 0) {
return error;
} else if (!error) {
- assert(t->proxy.cred);
+ GIT_ASSERT(t->proxy.cred);
winhttp_stream_close(s);
goto replay;
}
@@ -1256,7 +1289,7 @@
return -1;
}
- assert((DWORD)len == bytes_written);
+ GIT_ASSERT((DWORD)len == bytes_written);
return 0;
}
@@ -1355,7 +1388,7 @@
return -1;
}
- assert((DWORD)len == bytes_written);
+ GIT_ASSERT((DWORD)len == bytes_written);
s->post_body_len += bytes_written;
@@ -1562,7 +1595,7 @@
break;
default:
- assert(0);
+ GIT_ASSERT(0);
}
if (!ret)
diff -Nru cargo-0.47.0/debian/libgit2/src/tree.c cargo-0.51.0/debian/libgit2/src/tree.c
--- cargo-0.47.0/debian/libgit2/src/tree.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/tree.c 2021-04-07 03:36:48.000000000 +0000
@@ -228,7 +228,7 @@
{
git_tree_entry *cpy;
- assert(source);
+ GIT_ASSERT_ARG(source);
cpy = alloc_entry(source->filename, source->filename_len, source->oid);
if (cpy == NULL)
@@ -261,19 +261,19 @@
const char *git_tree_entry_name(const git_tree_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return entry->filename;
}
const git_oid *git_tree_entry_id(const git_tree_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, NULL);
return entry->oid;
}
git_object_t git_tree_entry_type(const git_tree_entry *entry)
{
- assert(entry);
+ GIT_ASSERT_ARG_WITH_RETVAL(entry, GIT_OBJECT_INVALID);
if (S_ISGITLINK(entry->attr))
return GIT_OBJECT_COMMIT;
@@ -288,7 +288,9 @@
git_repository *repo,
const git_tree_entry *entry)
{
- assert(entry && object_out);
+ GIT_ASSERT_ARG(entry);
+ GIT_ASSERT_ARG(object_out);
+
return git_object_lookup(object_out, repo, entry->oid, GIT_OBJECT_ANY);
}
@@ -306,7 +308,8 @@
const git_tree_entry *git_tree_entry_byname(
const git_tree *tree, const char *filename)
{
- assert(tree && filename);
+ GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL);
return entry_fromname(tree, filename, strlen(filename));
}
@@ -314,7 +317,7 @@
const git_tree_entry *git_tree_entry_byindex(
const git_tree *tree, size_t idx)
{
- assert(tree);
+ GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
return git_array_get(tree->entries, idx);
}
@@ -324,7 +327,7 @@
size_t i;
const git_tree_entry *e;
- assert(tree);
+ GIT_ASSERT_ARG_WITH_RETVAL(tree, NULL);
git_array_foreach(tree->entries, i, e) {
if (memcmp(&e->oid->id, &id->id, sizeof(id->id)) == 0)
@@ -336,13 +339,13 @@
size_t git_tree_entrycount(const git_tree *tree)
{
- assert(tree);
+ GIT_ASSERT_ARG_WITH_RETVAL(tree, 0);
return tree->entries.size;
}
size_t git_treebuilder_entrycount(git_treebuilder *bld)
{
- assert(bld);
+ GIT_ASSERT_ARG_WITH_RETVAL(bld, 0);
return git_strmap_size(bld->map);
}
@@ -626,7 +629,9 @@
git_buf shared_buf = GIT_BUF_INIT;
bool old_ignore_case = false;
- assert(oid && index && repo);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(index);
+ GIT_ASSERT_ARG(repo);
if (git_index_has_conflicts(index)) {
git_error_set(GIT_ERROR_INDEX,
@@ -680,7 +685,8 @@
git_treebuilder *bld;
size_t i;
- assert(builder_p && repo);
+ GIT_ASSERT_ARG(builder_p);
+ GIT_ASSERT_ARG(repo);
bld = git__calloc(1, sizeof(git_treebuilder));
GIT_ERROR_CHECK_ALLOC(bld);
@@ -723,7 +729,9 @@
git_tree_entry *entry;
int error;
- assert(bld && id && filename);
+ GIT_ASSERT_ARG(bld);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(filename);
if ((error = check_entry(bld->repo, filename, id, filemode)) < 0)
return error;
@@ -751,7 +759,9 @@
static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
{
- assert(bld && filename);
+ GIT_ASSERT_ARG_WITH_RETVAL(bld, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(filename, NULL);
+
return git_strmap_get(bld->map, filename);
}
@@ -792,8 +802,8 @@
git_tree_entry *entry;
git_vector entries = GIT_VECTOR_INIT;
- assert(bld);
- assert(tree);
+ GIT_ASSERT_ARG(bld);
+ GIT_ASSERT_ARG(tree);
git_buf_clear(tree);
@@ -842,7 +852,8 @@
const char *filename;
git_tree_entry *entry;
- assert(bld && filter);
+ GIT_ASSERT_ARG(bld);
+ GIT_ASSERT_ARG(filter);
git_strmap_foreach(bld->map, filename, entry, {
if (filter(entry, payload)) {
@@ -858,7 +869,7 @@
{
git_tree_entry *e;
- assert(bld);
+ GIT_ASSERT_ARG(bld);
git_strmap_foreach_value(bld->map, e, git_tree_entry_free(e));
git_strmap_clear(bld->map);
@@ -1174,10 +1185,10 @@
for (j = 0; j < steps_up; j++) {
tree_stack_entry *current, *popped = git_array_pop(stack);
- assert(popped);
+ GIT_ASSERT(popped);
current = git_array_last(stack);
- assert(current);
+ GIT_ASSERT(current);
if ((error = create_popped_tree(current, popped, &component)) < 0)
goto cleanup;
diff -Nru cargo-0.47.0/debian/libgit2/src/tsort.c cargo-0.51.0/debian/libgit2/src/tsort.c
--- cargo-0.47.0/debian/libgit2/src/tsort.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/tsort.c 2021-04-07 03:36:48.000000000 +0000
@@ -29,8 +29,6 @@
int l, c, r;
void *lx, *cx;
- assert(size > 0);
-
l = 0;
r = (int)size - 1;
c = r >> 1;
diff -Nru cargo-0.47.0/debian/libgit2/src/unix/map.c cargo-0.51.0/debian/libgit2/src/unix/map.c
--- cargo-0.47.0/debian/libgit2/src/unix/map.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/unix/map.c 2021-04-07 03:36:48.000000000 +0000
@@ -66,8 +66,10 @@
int p_munmap(git_map *map)
{
- assert(map != NULL);
+ GIT_ASSERT_ARG(map);
munmap(map->data, map->len);
+ map->data = NULL;
+ map->len = 0;
return 0;
}
diff -Nru cargo-0.47.0/debian/libgit2/src/unix/posix.h cargo-0.51.0/debian/libgit2/src/unix/posix.h
--- cargo-0.47.0/debian/libgit2/src/unix/posix.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/unix/posix.h 2021-04-07 03:36:48.000000000 +0000
@@ -62,11 +62,23 @@
#define p_snprintf snprintf
#define p_mkstemp(p) mkstemp(p)
#define p_chdir(p) chdir(p)
-#define p_chmod(p,m) chmod(p, m)
#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)
diff -Nru cargo-0.47.0/debian/libgit2/src/unix/pthread.h cargo-0.51.0/debian/libgit2/src/unix/pthread.h
--- cargo-0.47.0/debian/libgit2/src/unix/pthread.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/unix/pthread.h 2021-04-07 03:36:48.000000000 +0000
@@ -12,7 +12,8 @@
pthread_t thread;
} git_thread;
-#define git_threads_init() (void)0
+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) \
diff -Nru cargo-0.47.0/debian/libgit2/src/util.c cargo-0.51.0/debian/libgit2/src/util.c
--- cargo-0.47.0/debian/libgit2/src/util.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/util.c 2021-04-07 03:36:48.000000000 +0000
@@ -13,6 +13,11 @@
# include "win32/utf-conv.h"
# include "win32/w32_buffer.h"
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include
+
# ifdef HAVE_QSORT_S
# include
# endif
@@ -22,57 +27,15 @@
# include
#endif
-void git_strarray_free(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));
-}
-
-int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
-{
- size_t i;
-
- assert(tgt && 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_free(tgt);
- memset(tgt, 0, sizeof(*tgt));
- return -1;
- }
-
- tgt->count++;
- }
-
- return 0;
-}
+#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;
- int c, ovfl, v, neg, ndig;
+ int64_t n, nn, v;
+ int c, ovfl, neg, ndig;
p = nptr;
neg = 0;
@@ -147,19 +110,11 @@
if (v >= base)
break;
v = neg ? -v : v;
- if (n > INT64_MAX / base || n < INT64_MIN / base) {
+ 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;
}
- nn = n * base;
- if ((v > 0 && nn > INT64_MAX - v) ||
- (v < 0 && nn < INT64_MIN - v)) {
- ovfl = 1;
- /* Keep on iterating until the end of this number */
- continue;
- }
- n = nn + v;
}
Return:
@@ -424,35 +379,48 @@
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);
+ for (j = 0; j < LINE_WIDTH; ++j, ++line) {
+ printf("%02x ", (unsigned char)*line & 0xFF);
- printf("| ");
+ 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");
+ 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);
+ 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(" ");
- 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");
}
printf("\n");
@@ -711,7 +679,7 @@
void *payload;
} git__qsort_r_glue;
-static int GIT_STDLIB_CALL git__qsort_r_glue_cmp(
+static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
void *payload, const void *a, const void *b)
{
git__qsort_r_glue *glue = payload;
@@ -810,7 +778,7 @@
4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0
};
-int git__utf8_charlen(const uint8_t *str, size_t str_len)
+static int util_utf8_charlen(const uint8_t *str, size_t str_len)
{
size_t length, i;
@@ -835,7 +803,7 @@
int32_t uc = -1;
*dst = -1;
- length = git__utf8_charlen(str, str_len);
+ length = util_utf8_charlen(str, str_len);
if (length < 0)
return -1;
@@ -872,7 +840,7 @@
size_t offset = 0;
while (offset < str_len) {
- int length = git__utf8_charlen(str + offset, str_len - offset);
+ int length = util_utf8_charlen(str + offset, str_len - offset);
if (length < 0)
break;
@@ -926,3 +894,43 @@
return git_buf_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 -Nru cargo-0.47.0/debian/libgit2/src/util.h cargo-0.51.0/debian/libgit2/src/util.h
--- cargo-0.47.0/debian/libgit2/src/util.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/util.h 2021-04-07 03:36:48.000000000 +0000
@@ -18,7 +18,7 @@
#include "buffer.h"
#include "common.h"
#include "strnlen.h"
-#include "thread-utils.h"
+#include "thread.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
@@ -169,29 +169,29 @@
extern int git__strcasesort_cmp(const char *a, const char *b);
typedef struct {
- git_atomic refcount;
+ git_atomic32 refcount;
void *owner;
} git_refcount;
typedef void (*git_refcount_freeptr)(void *r);
#define GIT_REFCOUNT_INC(r) { \
- git_atomic_inc(&(r)->rc.refcount); \
+ git_atomic32_inc(&(r)->rc.refcount); \
}
#define GIT_REFCOUNT_DEC(_r, do_free) { \
git_refcount *r = &(_r)->rc; \
- int val = git_atomic_dec(&r->refcount); \
+ int val = git_atomic32_dec(&r->refcount); \
if (val <= 0 && r->owner == NULL) { do_free(_r); } \
}
#define GIT_REFCOUNT_OWN(r, o) { \
- (r)->rc.owner = o; \
+ (void)git_atomic_swap((r)->rc.owner, o); \
}
-#define GIT_REFCOUNT_OWNER(r) ((r)->rc.owner)
+#define GIT_REFCOUNT_OWNER(r) git_atomic_load((r)->rc.owner)
-#define GIT_REFCOUNT_VAL(r) git_atomic_get((r)->rc.refcount)
+#define GIT_REFCOUNT_VAL(r) git_atomic32_get((r)->rc.refcount)
static signed char from_hex[] = {
@@ -414,6 +414,10 @@
extern int git__getenv(git_buf *out, const char *name);
+extern int git__online_cpus(void);
+
+GIT_INLINE(int) git__noop(void) { return 0; }
+
#include "alloc.h"
#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/vector.c cargo-0.51.0/debian/libgit2/src/vector.c
--- cargo-0.47.0/debian/libgit2/src/vector.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/vector.c 2021-04-07 03:36:48.000000000 +0000
@@ -53,7 +53,8 @@
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
{
- assert(v && src);
+ GIT_ASSERT_ARG(v);
+ GIT_ASSERT_ARG(src);
v->_alloc_size = 0;
v->contents = NULL;
@@ -77,7 +78,8 @@
void git_vector_free(git_vector *v)
{
- assert(v);
+ if (!v)
+ return;
git__free(v->contents);
v->contents = NULL;
@@ -90,7 +92,8 @@
{
size_t i;
- assert(v);
+ if (!v)
+ return;
for (i = 0; i < v->length; ++i) {
git__free(v->contents[i]);
@@ -102,7 +105,7 @@
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
{
- assert(v);
+ GIT_ASSERT_ARG(v);
v->_alloc_size = 0;
v->_cmp = cmp;
@@ -131,7 +134,7 @@
int git_vector_insert(git_vector *v, void *element)
{
- assert(v);
+ GIT_ASSERT_ARG(v);
if (v->length >= v->_alloc_size &&
resize_vector(v, compute_new_size(v)) < 0)
@@ -150,7 +153,8 @@
int result;
size_t pos;
- assert(v && v->_cmp);
+ GIT_ASSERT_ARG(v);
+ GIT_ASSERT(v->_cmp);
if (!git_vector_is_sorted(v))
git_vector_sort(v);
@@ -180,8 +184,6 @@
void git_vector_sort(git_vector *v)
{
- assert(v);
-
if (git_vector_is_sorted(v) || !v->_cmp)
return;
@@ -196,7 +198,9 @@
git_vector_cmp key_lookup,
const void *key)
{
- assert(v && key && key_lookup);
+ GIT_ASSERT_ARG(v);
+ GIT_ASSERT_ARG(key);
+ GIT_ASSERT(key_lookup);
/* need comparison function to sort the vector */
if (!v->_cmp)
@@ -212,7 +216,9 @@
{
size_t i;
- assert(v && key && key_lookup);
+ 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) {
@@ -240,7 +246,7 @@
{
size_t shift_count;
- assert(v);
+ GIT_ASSERT_ARG(v);
if (idx >= v->length)
return GIT_ENOTFOUND;
@@ -303,7 +309,6 @@
void git_vector_clear(git_vector *v)
{
- assert(v);
v->length = 0;
git_vector_set_sorted(v, 1);
}
@@ -312,8 +317,6 @@
{
git_vector t;
- assert(a && b);
-
if (a != b) {
memcpy(&t, a, sizeof(t));
memcpy(a, b, sizeof(t));
@@ -340,7 +343,8 @@
{
size_t new_length;
- assert(insert_len > 0 && idx <= v->length);
+ GIT_ASSERT_ARG(insert_len > 0);
+ GIT_ASSERT_ARG(idx <= v->length);
GIT_ERROR_CHECK_ALLOC_ADD(&new_length, v->length, insert_len);
@@ -359,13 +363,13 @@
{
size_t new_length = v->length - remove_len;
size_t end_idx = 0;
-
- assert(remove_len > 0);
+
+ GIT_ASSERT_ARG(remove_len > 0);
if (git__add_sizet_overflow(&end_idx, idx, remove_len))
- assert(0);
+ GIT_ASSERT(0);
- assert(end_idx <= v->length);
+ GIT_ASSERT(end_idx <= v->length);
if (end_idx < v->length)
memmove(&v->contents[idx], &v->contents[end_idx],
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/findfile.c cargo-0.51.0/debian/libgit2/src/win32/findfile.c
--- cargo-0.47.0/debian/libgit2/src/win32/findfile.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/findfile.c 2021-04-07 03:36:48.000000000 +0000
@@ -53,7 +53,9 @@
{
wchar_t term, *base = path;
- assert(path && buf && buflen);
+ GIT_ASSERT_ARG_WITH_RETVAL(path, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(buf, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(buflen, NULL);
term = (*path == L'"') ? *path++ : L';';
@@ -109,7 +111,7 @@
HKEY hKey;
int error = GIT_ENOTFOUND;
- assert(buf);
+ GIT_ASSERT_ARG(buf);
if (!RegOpenKeyExW(hive, key, 0, KEY_READ, &hKey)) {
DWORD dwType, cbData;
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/git2.rc cargo-0.51.0/debian/libgit2/src/win32/git2.rc
--- cargo-0.47.0/debian/libgit2/src/win32/git2.rc 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/git2.rc 2021-04-07 03:36:48.000000000 +0000
@@ -2,14 +2,29 @@
#include "../../include/git2/version.h"
#ifndef LIBGIT2_FILENAME
-# define LIBGIT2_FILENAME "git2"
+# ifdef __GNUC__
+# define LIBGIT2_FILENAME git2
+# else
+# define LIBGIT2_FILENAME "git2"
+# endif
#endif
#ifndef LIBGIT2_COMMENTS
# define LIBGIT2_COMMENTS "For more information visit http://libgit2.github.com/"
#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_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
@@ -29,9 +44,9 @@
BEGIN
VALUE "FileDescription", "libgit2 - the Git linkable library\0"
VALUE "FileVersion", LIBGIT2_VERSION "\0"
- VALUE "InternalName", LIBGIT2_FILENAME ".dll\0"
+ VALUE "InternalName", STR(LIBGIT2_FILENAME) ".dll\0"
VALUE "LegalCopyright", "Copyright (C) the libgit2 contributors. All rights reserved.\0"
- VALUE "OriginalFilename", LIBGIT2_FILENAME ".dll\0"
+ VALUE "OriginalFilename", STR(LIBGIT2_FILENAME) ".dll\0"
VALUE "ProductName", "libgit2\0"
VALUE "ProductVersion", LIBGIT2_VERSION "\0"
VALUE "Comments", LIBGIT2_COMMENTS "\0"
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/map.c cargo-0.51.0/debian/libgit2/src/win32/map.c
--- cargo-0.47.0/debian/libgit2/src/win32/map.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/map.c 2021-04-07 03:36:48.000000000 +0000
@@ -117,7 +117,7 @@
{
int error = 0;
- assert(map != NULL);
+ GIT_ASSERT_ARG(map);
if (map->data) {
if (!UnmapViewOfFile(map->data)) {
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/msvc-compat.h cargo-0.51.0/debian/libgit2/src/win32/msvc-compat.h
--- cargo-0.47.0/debian/libgit2/src/win32/msvc-compat.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/msvc-compat.h 2021-04-07 03:36:48.000000000 +0000
@@ -23,6 +23,14 @@
#endif
-#define GIT_STDLIB_CALL __cdecl
+/*
+ * 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 -Nru cargo-0.47.0/debian/libgit2/src/win32/path_w32.c cargo-0.51.0/debian/libgit2/src/win32/path_w32.c
--- cargo-0.47.0/debian/libgit2/src/win32/path_w32.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/path_w32.c 2021-04-07 03:36:48.000000000 +0000
@@ -151,7 +151,7 @@
return (int)(to - path);
}
-int git_win32_path__cwd(wchar_t *out, size_t len)
+static int win32_path_cwd(wchar_t *out, size_t len)
{
int cwd_len;
@@ -241,7 +241,7 @@
else {
int cwd_len;
- if ((cwd_len = git_win32_path__cwd(dest, MAX_PATH)) < 0)
+ if ((cwd_len = win32_path_cwd(dest, MAX_PATH)) < 0)
goto on_error;
dest[cwd_len++] = L'\\';
@@ -492,14 +492,12 @@
prefix_len = CONST_STRLEN(unc_prefix);
}
- if (remainder) {
- /*
- * 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.)
- */
- assert(len >= remainder_len + prefix_len);
-
+ /*
+ * 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));
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/posix_w32.c cargo-0.51.0/debian/libgit2/src/win32/posix_w32.c
--- cargo-0.47.0/debian/libgit2/src/win32/posix_w32.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/posix_w32.c 2021-04-07 03:36:48.000000000 +0000
@@ -14,7 +14,6 @@
#include "utf-conv.h"
#include "repository.h"
#include "reparse.h"
-#include "global.h"
#include "buffer.h"
#include
#include
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/precompiled.h cargo-0.51.0/debian/libgit2/src/win32/precompiled.h
--- cargo-0.47.0/debian/libgit2/src/win32/precompiled.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/precompiled.h 2021-04-07 03:36:48.000000000 +0000
@@ -1,6 +1,5 @@
#include "common.h"
-#include
#include
#include
#include
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/thread.c cargo-0.51.0/debian/libgit2/src/win32/thread.c
--- cargo-0.47.0/debian/libgit2/src/win32/thread.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/thread.c 2021-04-07 03:36:48.000000000 +0000
@@ -6,8 +6,7 @@
*/
#include "thread.h"
-
-#include "../global.h"
+#include "runtime.h"
#define CLEAN_THREAD_EXIT 0x6F012842
@@ -19,6 +18,8 @@
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
@@ -28,14 +29,19 @@
git_thread *thread = lpParameter;
/* Set the current thread for `git_thread_exit` */
- GIT_GLOBAL->current_thread = thread;
+ FlsSetValue(fls_index, thread);
thread->result = thread->proc(thread->param);
return CLEAN_THREAD_EXIT;
}
-int git_threads_init(void)
+static void git_threads_global_shutdown(void)
+{
+ FlsFree(fls_index);
+}
+
+int git_threads_global_init(void)
{
HMODULE hModule = GetModuleHandleW(L"kernel32");
@@ -52,7 +58,10 @@
GetProcAddress(hModule, "ReleaseSRWLockExclusive");
}
- return 0;
+ if ((fls_index = FlsAlloc(NULL)) == FLS_OUT_OF_INDEXES)
+ return -1;
+
+ return git_runtime_shutdown_register(git_threads_global_shutdown);
}
int git_thread_create(
@@ -85,10 +94,7 @@
/* 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. */
- if (exit != CLEAN_THREAD_EXIT) {
- assert(false);
- thread->result = NULL;
- }
+ GIT_ASSERT(exit == CLEAN_THREAD_EXIT);
if (value_ptr)
*value_ptr = thread->result;
@@ -99,8 +105,11 @@
void git_thread_exit(void *value)
{
- assert(GIT_GLOBAL->current_thread);
- GIT_GLOBAL->current_thread->result = value;
+ git_thread *thread = FlsGetValue(fls_index);
+
+ if (thread)
+ thread->result = value;
+
ExitThread(CLEAN_THREAD_EXIT);
}
@@ -137,7 +146,7 @@
{
/* This is an auto-reset event. */
*cond = CreateEventW(NULL, FALSE, FALSE, NULL);
- assert(*cond);
+ 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(). */
@@ -152,7 +161,7 @@
return EINVAL;
closed = CloseHandle(*cond);
- assert(closed);
+ GIT_ASSERT(closed);
GIT_UNUSED(closed);
*cond = NULL;
@@ -174,7 +183,7 @@
return error;
wait_result = WaitForSingleObject(*cond, INFINITE);
- assert(WAIT_OBJECT_0 == wait_result);
+ GIT_ASSERT(WAIT_OBJECT_0 == wait_result);
GIT_UNUSED(wait_result);
return git_mutex_lock(mutex);
@@ -188,7 +197,7 @@
return EINVAL;
signaled = SetEvent(*cond);
- assert(signaled);
+ GIT_ASSERT(signaled);
GIT_UNUSED(signaled);
return 0;
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/thread.h cargo-0.51.0/debian/libgit2/src/win32/thread.h
--- cargo-0.47.0/debian/libgit2/src/win32/thread.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/thread.h 2021-04-07 03:36:48.000000000 +0000
@@ -35,7 +35,7 @@
} native;
} git_rwlock;
-int git_threads_init(void);
+int git_threads_global_init(void);
int git_thread_create(git_thread *GIT_RESTRICT,
void *(*) (void *),
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_buffer.c cargo-0.51.0/debian/libgit2/src/win32/w32_buffer.c
--- cargo-0.47.0/debian/libgit2/src/win32/w32_buffer.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_buffer.c 2021-04-07 03:36:48.000000000 +0000
@@ -32,13 +32,13 @@
return -1;
}
- assert(string_w);
+ 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;
- assert(utf8_len > 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);
@@ -50,7 +50,7 @@
CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0)
return handle_wc_error();
- assert(utf8_write_len == utf8_len);
+ GIT_ASSERT(utf8_write_len == utf8_len);
buf->size += utf8_write_len;
buf->ptr[buf->size] = '\0';
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.c cargo-0.51.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.c
--- cargo-0.47.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.c 1970-01-01 00:00:00.000000000 +0000
@@ -1,345 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * 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_crtdbg_stacktrace.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-#include "w32_stack.h"
-
-#define CRTDBG_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[CRTDBG_STACKTRACE__UID_LEN + 1];
-} git_win32__crtdbg_stacktrace__uid;
-
-/**
- * All mallocs with the same stacktrace will be de-duped
- * and aggregated into this row.
- */
-typedef struct {
- git_win32__crtdbg_stacktrace__uid uid; /* must be first */
- git_win32__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__crtdbg_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 (1024 * 1024)
-static git_win32__crtdbg_stacktrace__row g_cs_rows[MY_ROW_LIMIT];
-static git_win32__crtdbg_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__stack__raw_data *d1 = (git_win32__stack__raw_data*)v1;
- git_win32__crtdbg_stacktrace__row *r2 = (git_win32__crtdbg_stacktrace__row *)v2;
-
- return (git_win32__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__crtdbg_stacktrace__row * insert_unique(
- const git_win32__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__stack_format(
- buf, sizeof(buf), &g_cs_rows[k].raw_data,
- NULL, NULL) >= 0) {
- my_output(buf);
- }
-
- my_output("\n");
- }
- }
-
- fflush(stderr);
-}
-
-void git_win32__crtdbg_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__crtdbg_stacktrace__dump(
- git_win32__crtdbg_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__CRTDBG_STACKTRACE__SET_MARK);
- bool b_leaks_since_mark = IS_BIT_SET(opt, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK);
- bool b_leaks_total = IS_BIT_SET(opt, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL);
- bool b_quiet = IS_BIT_SET(opt, GIT_WIN32__CRTDBG_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;
-}
-
-void git_win32__crtdbg_stacktrace_cleanup(void)
-{
- /* At shutdown/cleanup, dump cummulative 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__crtdbg_stacktrace__dump(
- GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL,
- "CLEANUP");
-
- DeleteCriticalSection(&g_crtdbg_stacktrace_cs);
-}
-
-const char *git_win32__crtdbg_stacktrace(int skip, const char *file)
-{
- git_win32__stack__raw_data new_data;
- git_win32__crtdbg_stacktrace__row *row;
- const char * result = file;
-
- if (git_win32__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;
-}
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.h cargo-0.51.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.h
--- cargo-0.47.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_crtdbg_stacktrace.h 1970-01-01 00:00:00.000000000 +0000
@@ -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_w32_crtdbg_stacktrace_h__
-#define INCLUDE_win32_w32_crtdbg_stacktrace_h__
-
-#include "common.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-
-#include
-#include
-
-#include "git2/errors.h"
-#include "strnlen.h"
-
-/* 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.
- */
-
-/**
- * Initialize our memory leak tracking and de-dup data structures.
- * This should ONLY be called by git_libgit2_init().
- */
-void git_win32__crtdbg_stacktrace_init(void);
-
-/**
- * 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__crtdbg_stacktrace_cleanup(void);
-
-/**
- * Checkpoint options.
- */
-typedef enum git_win32__crtdbg_stacktrace_options {
- /**
- * Set checkpoint marker.
- */
- GIT_WIN32__CRTDBG_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__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK = (1 << 1),
-
- /**
- * Dump leaks since init. May not be combined
- * with __LEAKS_SINCE_MARK.
- */
- GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL = (1 << 2),
-
- /**
- * Suppress printing during dumps.
- * Just return leak count.
- */
- GIT_WIN32__CRTDBG_STACKTRACE__QUIET = (1 << 3),
-
-} git_win32__crtdbg_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.
- */
-GIT_EXTERN(int) git_win32__crtdbg_stacktrace__dump(
- git_win32__crtdbg_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__crtdbg_stacktrace(int skip, const char *file);
-
-#endif
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_leakcheck.c cargo-0.51.0/debian/libgit2/src/win32/w32_leakcheck.c
--- cargo-0.47.0/debian/libgit2/src/win32/w32_leakcheck.c 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_leakcheck.c 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,576 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * 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;
+}
+
+/* Strack 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 cummulative 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();
+}
+
+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 -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_leakcheck.h cargo-0.51.0/debian/libgit2/src/win32/w32_leakcheck.h
--- cargo-0.47.0/debian/libgit2/src/win32/w32_leakcheck.h 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_leakcheck.h 2020-12-20 21:25:22.000000000 +0000
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This 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 "common.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"
+
+/* 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 -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_stack.c cargo-0.51.0/debian/libgit2/src/win32/w32_stack.c
--- cargo-0.47.0/debian/libgit2/src/win32/w32_stack.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_stack.c 1970-01-01 00:00:00.000000000 +0000
@@ -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.
- */
-
-#include "w32_stack.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-#include "Windows.h"
-#include "Dbghelp.h"
-#include "win32/posix.h"
-#include "hash.h"
-
-static bool g_win32_stack_initialized = false;
-static HANDLE g_win32_stack_process = INVALID_HANDLE_VALUE;
-static git_win32__stack__aux_cb_alloc g_aux_cb_alloc = NULL;
-static git_win32__stack__aux_cb_lookup g_aux_cb_lookup = NULL;
-
-int git_win32__stack__set_aux_cb(
- git_win32__stack__aux_cb_alloc cb_alloc,
- git_win32__stack__aux_cb_lookup cb_lookup)
-{
- g_aux_cb_alloc = cb_alloc;
- g_aux_cb_lookup = cb_lookup;
-
- return 0;
-}
-
-void git_win32__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;
- }
-}
-
-void git_win32__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__stack_capture(git_win32__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__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__stack_compare(
- git_win32__stack__raw_data *d1,
- git_win32__stack__raw_data *d2)
-{
- return memcmp(d1, d2, sizeof(*d1));
-}
-
-int git_win32__stack_format(
- char *pbuf, size_t buf_len,
- const git_win32__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__stack(
- char * pbuf, size_t buf_len,
- int skip,
- const char *prefix, const char *suffix)
-{
- git_win32__stack__raw_data data;
- int error;
-
- if ((error = git_win32__stack_capture(&data, skip)) < 0)
- return error;
- if ((error = git_win32__stack_format(pbuf, buf_len, &data, prefix, suffix)) < 0)
- return error;
- return 0;
-}
-
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/win32/w32_stack.h cargo-0.51.0/debian/libgit2/src/win32/w32_stack.h
--- cargo-0.47.0/debian/libgit2/src/win32/w32_stack.h 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/win32/w32_stack.h 1970-01-01 00:00:00.000000000 +0000
@@ -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.
- */
-
-#ifndef INCLUDE_win32_w32_stack_h__
-#define INCLUDE_win32_w32_stack_h__
-
-#include "common.h"
-
-#if defined(GIT_MSVC_CRTDBG)
-
-/**
- * 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__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__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.
- */
-GIT_EXTERN(int) git_win32__stack__set_aux_cb(
- git_win32__stack__aux_cb_alloc cb_alloc,
- git_win32__stack__aux_cb_lookup cb_lookup);
-
-/**
- * Maximum number of stackframes to record for a
- * single stacktrace.
- */
-#define GIT_WIN32__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__STACK__MAX_FRAMES];
-} git_win32__stack__raw_data;
-
-
-/**
- * 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__stack_init(void);
-
-/**
- * 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__stack_cleanup(void);
-
-
-/**
- * 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__stack_capture(git_win32__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__stack_compare(
- git_win32__stack__raw_data *d1,
- git_win32__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__stack_format(
- char *pbuf, size_t buf_len,
- const git_win32__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__stack(
- char * pbuf, size_t buf_len,
- int skip,
- const char *prefix, const char *suffix);
-
-#endif /* GIT_MSVC_CRTDBG */
-#endif
diff -Nru cargo-0.47.0/debian/libgit2/src/worktree.c cargo-0.51.0/debian/libgit2/src/worktree.c
--- cargo-0.47.0/debian/libgit2/src/worktree.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/worktree.c 2021-04-07 03:36:48.000000000 +0000
@@ -37,7 +37,8 @@
size_t i, len;
int error;
- assert(wts && repo);
+ GIT_ASSERT_ARG(wts);
+ GIT_ASSERT_ARG(repo);
wts->count = 0;
wts->strings = NULL;
@@ -73,7 +74,8 @@
{
git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
- assert(base && file);
+ GIT_ASSERT_ARG_WITH_RETVAL(base, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(file, NULL);
if (git_buf_joinpath(&path, base, file) < 0)
goto err;
@@ -106,7 +108,9 @@
git_buf path = GIT_BUF_INIT;
int err;
- assert(base && file && buf);
+ GIT_ASSERT_ARG(base);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(buf);
if ((err = git_buf_joinpath(&path, base, file)) < 0)
goto out;
@@ -170,7 +174,8 @@
git_worktree *wt = NULL;
int error;
- assert(repo && name);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
*out = NULL;
@@ -237,7 +242,7 @@
int git_worktree_validate(const git_worktree *wt)
{
- assert(wt);
+ GIT_ASSERT_ARG(wt);
if (!is_worktree_dir(wt->gitdir_path)) {
git_error_set(GIT_ERROR_WORKTREE,
@@ -259,7 +264,14 @@
wt->commondir_path);
return GIT_ERROR;
}
-
+
+ if (!git_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;
}
@@ -271,11 +283,13 @@
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,
@@ -295,7 +309,10 @@
if (opts)
memcpy(&wtopts, opts, sizeof(wtopts));
- assert(out && repo && name && worktree);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
+ GIT_ASSERT_ARG(worktree);
*out = NULL;
@@ -408,7 +425,7 @@
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
int error;
- assert(wt);
+ GIT_ASSERT_ARG(wt);
if ((error = git_worktree_is_locked(NULL, wt)) < 0)
goto out;
@@ -439,7 +456,7 @@
git_buf path = GIT_BUF_INIT;
int error;
- assert(wt);
+ GIT_ASSERT_ARG(wt);
if ((error = git_worktree_is_locked(NULL, wt)) < 0)
return error;
@@ -466,7 +483,7 @@
git_buf path = GIT_BUF_INIT;
int error, locked;
- assert(wt);
+ GIT_ASSERT_ARG(wt);
if (reason)
git_buf_clear(reason);
@@ -487,13 +504,13 @@
const char *git_worktree_name(const git_worktree *wt)
{
- assert(wt);
+ GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
return wt->name;
}
const char *git_worktree_path(const git_worktree *wt)
{
- assert(wt);
+ GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
return wt->worktree_path;
}
@@ -506,11 +523,13 @@
return 0;
}
-int git_worktree_pruneinit_options(git_worktree_prune_options *opts,
+#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)
diff -Nru cargo-0.47.0/debian/libgit2/src/zstream.c cargo-0.51.0/debian/libgit2/src/zstream.c
--- cargo-0.47.0/debian/libgit2/src/zstream.c 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/libgit2/src/zstream.c 2021-04-07 03:36:48.000000000 +0000
@@ -156,7 +156,7 @@
}
/* either we finished the input or we did not flush the data */
- assert(zstream->in_len > 0 || zstream->flush == Z_FINISH);
+ 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;
diff -Nru cargo-0.47.0/debian/patches/0001-relax-deprecated-diagnostic-message-check.patch cargo-0.51.0/debian/patches/0001-relax-deprecated-diagnostic-message-check.patch
--- cargo-0.47.0/debian/patches/0001-relax-deprecated-diagnostic-message-check.patch 2020-12-08 21:58:04.000000000 +0000
+++ cargo-0.51.0/debian/patches/0001-relax-deprecated-diagnostic-message-check.patch 1970-01-01 00:00:00.000000000 +0000
@@ -1,39 +0,0 @@
-From 537a0202679b9ccd2a951d2695a2ad7b18b16415 Mon Sep 17 00:00:00 2001
-From: Andy Russell
-Date: Thu, 30 Jul 2020 21:04:22 -0400
-Subject: [PATCH] relax deprecated diagnostic message check
-
----
- tests/testsuite/fix.rs | 6 +++---
- 1 file changed, 3 insertions(+), 3 deletions(-)
-
-diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs
-index 3a293cfc2..c54cd77c0 100644
---- a/tests/testsuite/fix.rs
-+++ b/tests/testsuite/fix.rs
-@@ -686,7 +686,7 @@ fn shows_warnings() {
- .build();
-
- p.cargo("fix --allow-no-vcs")
-- .with_stderr_contains("[..]warning: use of deprecated item[..]")
-+ .with_stderr_contains("[..]warning: use of deprecated[..]")
- .run();
- }
-
-@@ -929,11 +929,11 @@ fn shows_warnings_on_second_run_without_changes() {
- .build();
-
- p.cargo("fix --allow-no-vcs")
-- .with_stderr_contains("[..]warning: use of deprecated item[..]")
-+ .with_stderr_contains("[..]warning: use of deprecated[..]")
- .run();
-
- p.cargo("fix --allow-no-vcs")
-- .with_stderr_contains("[..]warning: use of deprecated item[..]")
-+ .with_stderr_contains("[..]warning: use of deprecated[..]")
- .run();
- }
-
---
-2.25.1
-
diff -Nru cargo-0.47.0/debian/patches/2003_disable_close_output.patch cargo-0.51.0/debian/patches/2003_disable_close_output.patch
--- cargo-0.47.0/debian/patches/2003_disable_close_output.patch 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/patches/2003_disable_close_output.patch 2021-03-04 03:06:47.000000000 +0000
@@ -0,0 +1,21 @@
+Description:
+ Disable close_output, it is flaky.
+ .
+ It is already fixed upstream in #8587 and #8668, however these depend on
+ subsequent changes to the same file and is hard to backport. So just disable
+ it for now in Debian, it is a test problem not a cargo problem.
+ .
+ FIXME remove this patch in cargo 0.49 which contains those above FRs.
+--- a/tests/testsuite/build.rs
++++ b/tests/testsuite/build.rs
+@@ -5133,8 +5133,8 @@
+ p.process(&p.bin("foo")).run();
+ }
+
+-#[cargo_test]
+-fn close_output() {
++#[allow(dead_code)]
++fn _close_output() {
+ // What happens when stdout or stderr is closed during a build.
+
+ // Server to know when rustc has spawned.
diff -Nru cargo-0.47.0/debian/patches/2005_disable_fetch_cross_tests.patch cargo-0.51.0/debian/patches/2005_disable_fetch_cross_tests.patch
--- cargo-0.47.0/debian/patches/2005_disable_fetch_cross_tests.patch 2020-05-27 21:31:05.000000000 +0000
+++ cargo-0.51.0/debian/patches/2005_disable_fetch_cross_tests.patch 1970-01-01 00:00:00.000000000 +0000
@@ -1,30 +0,0 @@
-Description: Disable fetch tests to allow build on arm and ppc architecture
- These tests are disabled to allow building on release architecture.
-Author: Vasudev Kamath
-Bug: https://github.com/rust-lang/cargo/issues/5864
-Last-Update: 2018-08-05
-
---- a/tests/testsuite/fetch.rs
-+++ b/tests/testsuite/fetch.rs
-@@ -14,8 +14,8 @@
- p.cargo("fetch").with_stdout("").run();
- }
-
--#[cargo_test]
--fn fetch_all_platform_dependencies_when_no_target_is_given() {
-+#[allow(dead_code)]
-+fn _fetch_all_platform_dependencies_when_no_target_is_given() {
- if cross_compile::disabled() {
- return;
- }
-@@ -61,8 +61,8 @@
- .run();
- }
-
--#[cargo_test]
--fn fetch_platform_specific_dependencies() {
-+#[allow(dead_code)]
-+fn _fetch_platform_specific_dependencies() {
- if cross_compile::disabled() {
- return;
- }
diff -Nru cargo-0.47.0/debian/patches/series cargo-0.51.0/debian/patches/series
--- cargo-0.47.0/debian/patches/series 2020-12-08 21:58:04.000000000 +0000
+++ cargo-0.51.0/debian/patches/series 2021-04-19 23:06:45.000000000 +0000
@@ -1,5 +1,5 @@
2002_disable-net-tests.patch
-2005_disable_fetch_cross_tests.patch
-use-system-libhttp-parser.patch
-0001-relax-deprecated-diagnostic-message-check.patch
+2003_disable_close_output.patch
skip-filters_target-i386.patch
+skip-filter_platform-non-amd64.patch
+use-system-libhttp-parser.patch
diff -Nru cargo-0.47.0/debian/patches/skip-filter_platform-non-amd64.patch cargo-0.51.0/debian/patches/skip-filter_platform-non-amd64.patch
--- cargo-0.47.0/debian/patches/skip-filter_platform-non-amd64.patch 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/debian/patches/skip-filter_platform-non-amd64.patch 2021-03-05 02:29:13.000000000 +0000
@@ -0,0 +1,11 @@
+https://github.com/rust-lang/cargo/issues/9238
+--- a/tests/testsuite/metadata.rs
++++ b/tests/testsuite/metadata.rs
+@@ -2047,6 +2047,7 @@
+ }
+
+ #[cargo_test]
++#[cfg(target_arch = "x86_64")]
+ fn filter_platform() {
+ // Testing the --filter-platform flag.
+ Package::new("normal-dep", "0.0.1").publish();
diff -Nru cargo-0.47.0/debian/patches/skip-filters_target-i386.patch cargo-0.51.0/debian/patches/skip-filters_target-i386.patch
--- cargo-0.47.0/debian/patches/skip-filters_target-i386.patch 2020-12-08 21:58:04.000000000 +0000
+++ cargo-0.51.0/debian/patches/skip-filters_target-i386.patch 2021-03-04 03:06:47.000000000 +0000
@@ -1,10 +1,10 @@
--- a/tests/testsuite/tree.rs
+++ b/tests/testsuite/tree.rs
-@@ -322,6 +322,7 @@
+@@ -355,6 +355,7 @@
}
#[cargo_test]
+#[cfg(not(target_arch = "x86"))]
fn filters_target() {
// --target flag
- Package::new("targetdep", "1.0.0").publish();
+ if cross_compile::disabled() {
diff -Nru cargo-0.47.0/debian/patches/use-system-libhttp-parser.patch cargo-0.51.0/debian/patches/use-system-libhttp-parser.patch
--- cargo-0.47.0/debian/patches/use-system-libhttp-parser.patch 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/patches/use-system-libhttp-parser.patch 2021-04-07 03:36:48.000000000 +0000
@@ -1,6 +1,6 @@
--- a/vendor/libgit2-sys/build.rs
+++ b/vendor/libgit2-sys/build.rs
-@@ -46,32 +46,11 @@
+@@ -51,32 +51,11 @@
add_c_files(&mut cfg, "libgit2/src/transports");
add_c_files(&mut cfg, "libgit2/src/streams");
@@ -35,5 +35,5 @@
- // when when COMPILE_PCRE8 is not defined, which is the default.
- add_c_files(&mut cfg, "libgit2/deps/pcre");
+ cfg.file("libgit2/src/allocators/failalloc.c");
cfg.file("libgit2/src/allocators/stdalloc.c");
-
diff -Nru cargo-0.47.0/debian/README.source cargo-0.51.0/debian/README.source
--- cargo-0.47.0/debian/README.source 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/README.source 2021-04-07 03:36:48.000000000 +0000
@@ -1,8 +1,8 @@
Embedded libraries
==================
-The source package embeds a copy of libgit2 0.28.3 because that is what this
-version of cargo needs, but this is newer than the version in Ubuntu 19.10 and
+The source package embeds a copy of libgit2 1.1.0 because that is what this
+version of cargo needs, but this is newer than the version in Ubuntu 20.10 and
older.
Updating the package
diff -Nru cargo-0.47.0/debian/rules cargo-0.51.0/debian/rules
--- cargo-0.47.0/debian/rules 2020-12-03 20:53:35.000000000 +0000
+++ cargo-0.51.0/debian/rules 2021-04-07 03:36:48.000000000 +0000
@@ -14,6 +14,11 @@
export DEB_CARGO_CRATE=cargo_$(DEB_VERSION_UPSTREAM)
export RUSTFLAGS += --remap-path-prefix=$(CURDIR)=/usr/src/cargo-$(DEB_VERSION_UPSTREAM)
+# https://github.com/rust-lang/rust/issues/52108
+ifneq (,$(filter $(DEB_HOST_ARCH), mips64el))
+ RUSTFLAGS += -Ctarget-feature=+xgot
+endif
+
# don't shrink, this can take ages
# see https://github.com/rust-lang/cargo/issues/6490 for details
export PROPTEST_MAX_SHRINK_ITERS = 0
diff -Nru cargo-0.47.0/.github/ISSUE_TEMPLATE/tracking_issue.md cargo-0.51.0/.github/ISSUE_TEMPLATE/tracking_issue.md
--- cargo-0.47.0/.github/ISSUE_TEMPLATE/tracking_issue.md 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/.github/ISSUE_TEMPLATE/tracking_issue.md 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,34 @@
+---
+name: Tracking Issue
+about: A tracking issue for an accepted feature or RFC in Cargo.
+title: Tracking Issue for XXX
+labels: C-tracking-issue
+---
+
+
+**About tracking issues**
+
+Tracking issues are used to record the overall progress of implementation.
+They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
+A tracking issue is however *not* meant for large scale discussion, questions, or bug reports about a feature.
+Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
+
+**Summary**
+
+Original issue: #NNNN
+Implementation: #NNNN
+Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#my-feature
+
+
+
+**Unresolved issues**
+
+* [ ] Make a list of any known implementation or design issues.
+
+**Future extensions**
+
+
diff -Nru cargo-0.47.0/.github/workflows/contrib.yml cargo-0.51.0/.github/workflows/contrib.yml
--- cargo-0.47.0/.github/workflows/contrib.yml 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/.github/workflows/contrib.yml 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,33 @@
+name: Contrib Deploy
+on:
+ push:
+ branches:
+ - master
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+ - name: Install mdbook
+ run: |
+ mkdir mdbook
+ curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.3/mdbook-v0.4.3-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
+ echo `pwd`/mdbook >> $GITHUB_PATH
+ - name: Deploy docs
+ run: |
+ cd src/doc/contrib
+ mdbook build
+ git worktree add gh-pages gh-pages
+ git config user.name "Deploy from CI"
+ git config user.email ""
+ cd gh-pages
+ # Delete the ref to avoid keeping history.
+ git update-ref -d refs/heads/gh-pages
+ rm -rf contrib
+ mv ../book contrib
+ git add contrib
+ git commit -m "Deploy $GITHUB_SHA to gh-pages"
+ git push --force
diff -Nru cargo-0.47.0/.github/workflows/main.yml cargo-0.51.0/.github/workflows/main.yml
--- cargo-0.47.0/.github/workflows/main.yml 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/.github/workflows/main.yml 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,129 @@
+name: CI
+on:
+ push:
+ branches-ignore: [master]
+ pull_request:
+ branches: ['*']
+
+defaults:
+ run:
+ shell: bash
+
+jobs:
+ # Check Code style quickly by running `rustfmt` over all code
+ rustfmt:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update stable && rustup default stable
+ - run: rustup component add rustfmt
+ - run: cargo fmt --all -- --check
+ - run: |
+ for manifest in `find crates -name Cargo.toml`
+ do
+ echo check fmt for $manifest
+ cargo fmt --all --manifest-path $manifest -- --check
+ done
+
+ test:
+ runs-on: ${{ matrix.os }}
+ env:
+ CARGO_PROFILE_DEV_DEBUG: 1
+ CARGO_PROFILE_TEST_DEBUG: 1
+ CARGO_INCREMENTAL: 0
+ strategy:
+ matrix:
+ include:
+ - os: ubuntu-latest
+ rust: stable
+ other: i686-unknown-linux-gnu
+ - os: ubuntu-latest
+ rust: beta
+ other: i686-unknown-linux-gnu
+ - os: ubuntu-latest
+ rust: nightly
+ other: i686-unknown-linux-gnu
+ - os: macos-latest
+ rust: stable
+ other: x86_64-apple-ios
+ - os: windows-latest
+ rust: stable-msvc
+ other: i686-pc-windows-msvc
+ - os: windows-latest
+ rust: nightly-gnu
+ other: i686-pc-windows-gnu
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
+ - run: rustup target add ${{ matrix.other }}
+ - run: rustup component add rustc-dev llvm-tools-preview rust-docs
+ if: startsWith(matrix.rust, 'nightly')
+ - run: sudo apt update -y && sudo apt install gcc-multilib libsecret-1-0 libsecret-1-dev -y
+ if: matrix.os == 'ubuntu-latest'
+ - run: rustup component add rustfmt || echo "rustfmt not available"
+
+ # Deny warnings on CI to avoid warnings getting into the codebase.
+ - run: cargo test --features 'deny-warnings'
+ - run: cargo test --features 'deny-warnings' -p cargo-test-support
+ - run: cargo test -p cargo-platform
+ - run: cargo test --manifest-path crates/mdman/Cargo.toml
+ - run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml
+ - run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml
+ if: matrix.os == 'ubuntu-latest'
+ - run: cargo build --manifest-path crates/credential/cargo-credential-macos-keychain/Cargo.toml
+ if: matrix.os == 'macos-latest'
+ - run: cargo build --manifest-path crates/credential/cargo-credential-wincred/Cargo.toml
+ if: matrix.os == 'windows-latest'
+
+ resolver:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update stable && rustup default stable
+ - run: cargo test --manifest-path crates/resolver-tests/Cargo.toml
+
+ build_std:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update nightly && rustup default nightly
+ - run: rustup component add rust-src
+ - run: cargo build
+ - run: cargo test --test build-std
+ env:
+ CARGO_RUN_BUILD_STD_TESTS: 1
+ docs:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - run: rustup update nightly && rustup default nightly
+ - run: rustup component add rust-docs
+ - run: ci/validate-man.sh
+ # This requires rustfmt, use stable.
+ - run: cd src/doc/semver-check && cargo +stable run
+ - run: |
+ mkdir mdbook
+ curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.3.7/mdbook-v0.3.7-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
+ echo `pwd`/mdbook >> $GITHUB_PATH
+ - run: cargo doc --no-deps
+ - run: cd src/doc && mdbook build --dest-dir ../../target/doc
+ - run: |
+ cd src/doc
+ curl -sSLo linkcheck.sh \
+ https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
+ sh linkcheck.sh --all cargo
+
+ success:
+ name: bors build finished
+ needs: [docs, rustfmt, test, resolver, build_std]
+ runs-on: ubuntu-latest
+ if: "success() && github.event_name == 'push' && github.ref == 'refs/heads/auto-cargo'"
+ steps:
+ - run: echo ok
+ failure:
+ name: bors build finished
+ needs: [docs, rustfmt, test, resolver, build_std]
+ runs-on: ubuntu-latest
+ if: "!success() && github.event_name == 'push' && github.ref == 'refs/heads/auto-cargo'"
+ steps:
+ - run: exit 1
diff -Nru cargo-0.47.0/publish.py cargo-0.51.0/publish.py
--- cargo-0.47.0/publish.py 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/publish.py 2021-02-04 15:18:32.000000000 +0000
@@ -5,6 +5,7 @@
import os
import re
import subprocess
+import time
import urllib.request
from urllib.error import HTTPError
@@ -32,17 +33,20 @@
version = re.search('^version = "([^"]+)"', content, re.M).group(1)
if already_published(name, version):
print('%s %s is already published, skipping' % (name, version))
- return
+ return False
subprocess.check_call(['cargo', 'publish', '--no-verify'], cwd=path)
+ return True
def main():
- print('Doing dry run first...')
- for path in TO_PUBLISH:
- subprocess.check_call(['cargo', 'publish', '--no-verify', '--dry-run'], cwd=path)
print('Starting publish...')
- for path in TO_PUBLISH:
- maybe_publish(path)
+ for i, path in enumerate(TO_PUBLISH):
+ if maybe_publish(path):
+ if i < len(TO_PUBLISH)-1:
+ # Sleep to allow the index to update. This should probably
+ # check that the index is updated, or use a retry loop
+ # instead.
+ time.sleep(5)
print('Publish complete!')
diff -Nru cargo-0.47.0/README.md cargo-0.51.0/README.md
--- cargo-0.47.0/README.md 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/README.md 2021-02-04 15:18:32.000000000 +0000
@@ -66,8 +66,10 @@
## Contributing
-See [CONTRIBUTING.md](CONTRIBUTING.md). You may also find the architecture
-documentation useful ([ARCHITECTURE.md](ARCHITECTURE.md)).
+See the **[Cargo Contributor Guide]** for a complete introduction
+to contributing to Cargo.
+
+[Cargo Contributor Guide]: https://rust-lang.github.io/cargo/contrib/
## License
diff -Nru cargo-0.47.0/src/bin/cargo/cli.rs cargo-0.51.0/src/bin/cargo/cli.rs
--- cargo-0.47.0/src/bin/cargo/cli.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/cli.rs 2021-02-04 15:18:32.000000000 +0000
@@ -10,6 +10,11 @@
// CAUTION: Be careful with using `config` until it is configured below.
// In general, try to avoid loading config values unless necessary (like
// the [alias] table).
+
+ if commands::help::handle_embedded_help(config) {
+ return Ok(());
+ }
+
let args = match cli().get_matches_safe() {
Ok(args) => args,
Err(e) => {
@@ -30,13 +35,15 @@
"
Available unstable (nightly-only) flags:
- -Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
- -Z minimal-versions -- Install minimal dependency versions instead of maximum
- -Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
- -Z unstable-options -- Allow the usage of unstable options
- -Z timings -- Display concurrency information
- -Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
- -Z crate-versions -- Add crate versions to generated docs
+ -Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
+ -Z minimal-versions -- Install minimal dependency versions instead of maximum
+ -Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
+ -Z unstable-options -- Allow the usage of unstable options
+ -Z timings -- Display concurrency information
+ -Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
+ -Z terminal-width -- Provide a terminal width to rustc for error truncation
+ -Z namespaced-features -- Allow features with `dep:` prefix
+ -Z weak-dep-features -- Allow `dep_name?/feature` feature syntax
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
@@ -113,7 +120,7 @@
pub fn get_version_string(is_verbose: bool) -> String {
let version = cargo::version();
let mut version_string = version.to_string();
- version_string.push_str("\n");
+ version_string.push('\n');
if is_verbose {
version_string.push_str(&format!(
"release: {}.{}.{}\n",
diff -Nru cargo-0.47.0/src/bin/cargo/commands/bench.rs cargo-0.51.0/src/bin/cargo/commands/bench.rs
--- cargo-0.47.0/src/bin/cargo/commands/bench.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/bench.rs 2021-02-04 15:18:32.000000000 +0000
@@ -45,30 +45,7 @@
"Run all benchmarks regardless of failure",
))
.arg_unit_graph()
- .after_help(
- "\
-The benchmark filtering argument BENCHNAME and all the arguments following the
-two dashes (`--`) are passed to the benchmark binaries and thus to libtest
-(rustc's built in unit-test and micro-benchmarking framework). If you're
-passing arguments to both Cargo and the binary, the ones after `--` go to the
-binary, the ones before go to Cargo. For details about libtest's arguments see
-the output of `cargo bench -- --help`.
-
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package should be benchmarked. If it is not given, then
-the current package is benchmarked. For more information on SPEC and its format,
-see the `cargo help pkgid` command.
-
-All packages in the workspace are benchmarked if the `--workspace` flag is supplied. The
-`--workspace` flag is automatically assumed for a virtual manifest.
-Note that `--exclude` has to be specified in conjunction with the `--workspace` flag.
-
-The `--jobs` argument affects the building of the benchmark executable but does
-not affect how many jobs are used when running the benchmarks.
-
-Compilation can be customized with the `bench` profile in the manifest.
-",
- )
+ .after_help("Run `cargo help bench` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/build.rs cargo-0.51.0/src/bin/cargo/commands/build.rs
--- cargo-0.47.0/src/bin/cargo/commands/build.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/build.rs 2021-02-04 15:18:32.000000000 +0000
@@ -42,17 +42,7 @@
.arg_message_format()
.arg_build_plan()
.arg_unit_graph()
- .after_help(
- "\
-All packages in the workspace are built if the `--workspace` flag is supplied. The
-`--workspace` flag is automatically assumed for a virtual manifest.
-Note that `--exclude` has to be specified in conjunction with the `--workspace` flag.
-
-Compilation can be configured via the use of profiles which are configured in
-the manifest. The default profile for this command is `dev`, but passing
-the --release flag will use the `release` profile instead.
-",
- )
+ .after_help("Run `cargo help build` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/check.rs cargo-0.51.0/src/bin/cargo/commands/check.rs
--- cargo-0.47.0/src/bin/cargo/commands/check.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/check.rs 2021-02-04 15:18:32.000000000 +0000
@@ -34,25 +34,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package should be built. If it is not given, then the
-current package is built. For more information on SPEC and its format, see the
-`cargo help pkgid` command.
-
-All packages in the workspace are checked if the `--workspace` flag is supplied. The
-`--workspace` flag is automatically assumed for a virtual manifest.
-Note that `--exclude` has to be specified in conjunction with the `--workspace` flag.
-
-Compilation can be configured via the use of profiles which are configured in
-the manifest. The default profile for this command is `dev`, but passing
-the `--release` flag will use the `release` profile instead.
-
-The `--profile test` flag can be used to check unit tests with the
-`#[cfg(test)]` attribute.
-",
- )
+ .after_help("Run `cargo help check` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/clean.rs cargo-0.51.0/src/bin/cargo/commands/clean.rs
--- cargo-0.47.0/src/bin/cargo/commands/clean.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/clean.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,6 +1,7 @@
use crate::command_prelude::*;
use cargo::ops::{self, CleanOptions};
+use cargo::util::print_available_packages;
pub fn cli() -> App {
subcommand("clean")
@@ -13,18 +14,16 @@
.arg_release("Whether or not to clean release artifacts")
.arg_profile("Clean artifacts of the specified profile")
.arg_doc("Whether or not to clean just the documentation directory")
- .after_help(
- "\
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package's artifacts should be cleaned out. If it is not
-given, then all packages' artifacts are removed. For more information on SPEC
-and its format, see the `cargo help pkgid` command.
-",
- )
+ .after_help("Run `cargo help clean` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
+
+ if args.is_present_with_zero_values("package") {
+ print_available_packages(&ws)?;
+ }
+
let opts = CleanOptions {
config,
spec: values(args, "package"),
diff -Nru cargo-0.47.0/src/bin/cargo/commands/doc.rs cargo-0.51.0/src/bin/cargo/commands/doc.rs
--- cargo-0.47.0/src/bin/cargo/commands/doc.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/doc.rs 2021-02-04 15:18:32.000000000 +0000
@@ -31,22 +31,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-By default the documentation for the local package and all dependencies is
-built. The output is all placed in `target/doc` in rustdoc's usual format.
-
-All packages in the workspace are documented if the `--workspace` flag is
-supplied. The `--workspace` flag is automatically assumed for a virtual
-manifest. Note that `--exclude` has to be specified in conjunction with the
-`--workspace` flag.
-
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package should be documented. If it is not given, then the
-current package is documented. For more information on SPEC and its format, see
-the `cargo help pkgid` command.
-",
- )
+ .after_help("Run `cargo help doc` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/fetch.rs cargo-0.51.0/src/bin/cargo/commands/fetch.rs
--- cargo-0.47.0/src/bin/cargo/commands/fetch.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/fetch.rs 2021-02-04 15:18:32.000000000 +0000
@@ -9,18 +9,7 @@
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg_manifest_path()
.arg_target_triple("Fetch dependencies for the target triple")
- .after_help(
- "\
-If a lock file is available, this command will ensure that all of the Git
-dependencies and/or registries dependencies are downloaded and locally
-available. The network is never touched after a `cargo fetch` unless
-the lock file changes.
-
-If the lock file is not available, then this is the equivalent of
-`cargo generate-lockfile`. A lock file is generated and dependencies are also
-all updated.
-",
- )
+ .after_help("Run `cargo help fetch` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/fix.rs cargo-0.51.0/src/bin/cargo/commands/fix.rs
--- cargo-0.47.0/src/bin/cargo/commands/fix.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/fix.rs 2021-02-04 15:18:32.000000000 +0000
@@ -72,37 +72,7 @@
.long("allow-staged")
.help("Fix code even if the working directory has staged changes"),
)
- .after_help(
- "\
-This Cargo subcommand will automatically take rustc's suggestions from
-diagnostics like warnings and apply them to your source code. This is intended
-to help automate tasks that rustc itself already knows how to tell you to fix!
-The `cargo fix` subcommand is also being developed for the Rust 2018 edition
-to provide code the ability to easily opt-in to the new edition without having
-to worry about any breakage.
-
-Executing `cargo fix` will under the hood execute `cargo check`. Any warnings
-applicable to your crate will be automatically fixed (if possible) and all
-remaining warnings will be displayed when the check process is finished. For
-example if you'd like to prepare for the 2018 edition, you can do so by
-executing:
-
- cargo fix --edition
-
-which behaves the same as `cargo check --all-targets`. Similarly if you'd like
-to fix code for different platforms you can do:
-
- cargo fix --edition --target x86_64-pc-windows-gnu
-
-or if your crate has optional features:
-
- cargo fix --edition --no-default-features --features foo
-
-If you encounter any problems with `cargo fix` or otherwise have any questions
-or feature requests please don't hesitate to file an issue at
-https://github.com/rust-lang/cargo
-",
- )
+ .after_help("Run `cargo help fix` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/generate_lockfile.rs cargo-0.51.0/src/bin/cargo/commands/generate_lockfile.rs
--- cargo-0.47.0/src/bin/cargo/commands/generate_lockfile.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/generate_lockfile.rs 2021-02-04 15:18:32.000000000 +0000
@@ -7,6 +7,7 @@
.about("Generate the lockfile for a package")
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg_manifest_path()
+ .after_help("Run `cargo help generate-lockfile` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/help.rs cargo-0.51.0/src/bin/cargo/commands/help.rs
--- cargo-0.47.0/src/bin/cargo/commands/help.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/help.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,130 @@
+use crate::aliased_command;
+use cargo::util::errors::CargoResult;
+use cargo::util::paths::resolve_executable;
+use cargo::Config;
+use flate2::read::GzDecoder;
+use std::ffi::OsString;
+use std::io::Read;
+use std::io::Write;
+use std::path::Path;
+
+const COMPRESSED_MAN: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/man.tgz"));
+
+/// Checks if the `help` command is being issued.
+///
+/// This runs before clap processing, because it needs to intercept the `help`
+/// command if a man page is available.
+///
+/// Returns `true` if a man page was displayed. In this case, Cargo should
+/// exit.
+pub fn handle_embedded_help(config: &Config) -> bool {
+ match try_help(config) {
+ Ok(true) => true,
+ Ok(false) => false,
+ Err(e) => {
+ log::warn!("man failed: {:?}", e);
+ false
+ }
+ }
+}
+
+fn try_help(config: &Config) -> CargoResult {
+ let mut args = std::env::args_os()
+ .skip(1)
+ .skip_while(|arg| arg.to_str().map_or(false, |s| s.starts_with('-')));
+ if !args
+ .next()
+ .map_or(false, |arg| arg.to_str() == Some("help"))
+ {
+ return Ok(false);
+ }
+ let subcommand = match args.next() {
+ Some(arg) => arg,
+ None => return Ok(false),
+ };
+ let subcommand = match subcommand.to_str() {
+ Some(s) => s,
+ None => return Ok(false),
+ };
+ // Check if this is a built-in command (or alias);
+ let subcommand = match check_alias(config, subcommand) {
+ Some(s) => s,
+ None => return Ok(false),
+ };
+ if resolve_executable(Path::new("man")).is_ok() {
+ let man = match extract_man(&subcommand, "1") {
+ Some(man) => man,
+ None => return Ok(false),
+ };
+ write_and_spawn(&man, "man")?;
+ } else {
+ let txt = match extract_man(&subcommand, "txt") {
+ Some(txt) => txt,
+ None => return Ok(false),
+ };
+ if resolve_executable(Path::new("less")).is_ok() {
+ write_and_spawn(&txt, "less")?;
+ } else if resolve_executable(Path::new("more")).is_ok() {
+ write_and_spawn(&txt, "more")?;
+ } else {
+ drop(std::io::stdout().write_all(&txt));
+ }
+ }
+ Ok(true)
+}
+
+/// Checks if the given subcommand is a built-in command (possibly via an alias).
+///
+/// Returns None if it is not a built-in command.
+fn check_alias(config: &Config, subcommand: &str) -> Option {
+ if super::builtin_exec(subcommand).is_some() {
+ return Some(subcommand.to_string());
+ }
+ match aliased_command(config, subcommand) {
+ Ok(Some(alias)) => {
+ let alias = alias.into_iter().next()?;
+ if super::builtin_exec(&alias).is_some() {
+ Some(alias)
+ } else {
+ None
+ }
+ }
+ _ => None,
+ }
+}
+
+/// Extracts the given man page from the compressed archive.
+///
+/// Returns None if the command wasn't found.
+fn extract_man(subcommand: &str, extension: &str) -> Option> {
+ let extract_name = OsString::from(format!("cargo-{}.{}", subcommand, extension));
+ let gz = GzDecoder::new(COMPRESSED_MAN);
+ let mut ar = tar::Archive::new(gz);
+ // Unwraps should be safe here, since this is a static archive generated
+ // by our build script. It should never be an invalid format!
+ for entry in ar.entries().unwrap() {
+ let mut entry = entry.unwrap();
+ let path = entry.path().unwrap();
+ if path.file_name().unwrap() != extract_name {
+ continue;
+ }
+ let mut result = Vec::new();
+ entry.read_to_end(&mut result).unwrap();
+ return Some(result);
+ }
+ None
+}
+
+/// Write the contents of a man page to disk and spawn the given command to
+/// display it.
+fn write_and_spawn(contents: &[u8], command: &str) -> CargoResult<()> {
+ let mut tmp = tempfile::Builder::new().prefix("cargo-man").tempfile()?;
+ let f = tmp.as_file_mut();
+ f.write_all(contents)?;
+ f.flush()?;
+ let mut cmd = std::process::Command::new(command)
+ .arg(tmp.path())
+ .spawn()?;
+ drop(cmd.wait());
+ Ok(())
+}
diff -Nru cargo-0.47.0/src/bin/cargo/commands/init.rs cargo-0.51.0/src/bin/cargo/commands/init.rs
--- cargo-0.47.0/src/bin/cargo/commands/init.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/init.rs 2021-02-04 15:18:32.000000000 +0000
@@ -9,6 +9,7 @@
.arg(Arg::with_name("path").default_value("."))
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
.arg_new_opts()
+ .after_help("Run `cargo help init` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/install.rs cargo-0.51.0/src/bin/cargo/commands/install.rs
--- cargo-0.47.0/src/bin/cargo/commands/install.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/install.rs 2021-02-04 15:18:32.000000000 +0000
@@ -71,39 +71,7 @@
.requires("crate")
.conflicts_with_all(&["git", "path", "index"]),
)
- .after_help(
- "\
-This command manages Cargo's local set of installed binary crates. Only
-packages which have executable [[bin]] or [[example]] targets can be
-installed, and all executables are installed into the installation root's
-`bin` folder. The installation root is determined, in order of precedence, by
-`--root`, `$CARGO_INSTALL_ROOT`, the `install.root` configuration key, and
-finally the home directory (which is either `$CARGO_HOME` if set or
-`$HOME/.cargo` by default).
-
-There are multiple sources from which a crate can be installed. The default
-location is crates.io but the `--git`, `--path`, and `--registry` flags can
-change this source. If the source contains more than one package (such as
-crates.io or a git repository with multiple crates) the `` argument is
-required to indicate which crate should be installed.
-
-Crates from crates.io can optionally specify the version they wish to install
-via the `--version` flags, and similarly packages from git repositories can
-optionally specify the branch, tag, or revision that should be installed. If a
-crate has multiple binaries, the `--bin` argument can selectively install only
-one of them, and if you'd rather install examples the `--example` argument can
-be used as well.
-
-If the package is already installed, Cargo will reinstall it if the installed
-version does not appear to be up-to-date. Installing with `--path` will always
-build and install, unless there are conflicting binaries from another package.
-
-If the source is crates.io or `--git` then by default the crate will be built
-in a temporary target directory. To avoid this, the target directory can be
-specified by setting the `CARGO_TARGET_DIR` environment variable to a relative
-path. In particular, this can be useful for caching build artifacts on
-continuous integration systems.",
- )
+ .after_help("Run `cargo help install` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
@@ -113,17 +81,6 @@
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
}
- let workspace = args.workspace(config).ok();
- let mut compile_opts = args.compile_options(
- config,
- CompileMode::Build,
- workspace.as_ref(),
- ProfileChecking::Checked,
- )?;
-
- compile_opts.build_config.requested_profile =
- args.get_profile_name(config, "release", ProfileChecking::Checked)?;
-
let krates = args
.values_of("crate")
.unwrap_or_default()
@@ -140,7 +97,7 @@
} else if let Some(rev) = args.value_of("rev") {
GitReference::Rev(rev.to_string())
} else {
- GitReference::Branch("master".to_string())
+ GitReference::DefaultBranch
};
SourceId::for_git(&url, gitref)?
} else if let Some(path) = args.value_of_path("path", config) {
@@ -159,6 +116,26 @@
let version = args.value_of("version");
let root = args.value_of("root");
+ // We only provide worksapce information for local crate installation from
+ // one of the following sources:
+ // - From current working directory (only work for edition 2015).
+ // - From a specific local file path.
+ let workspace = if from_cwd || args.is_present("path") {
+ args.workspace(config).ok()
+ } else {
+ None
+ };
+
+ let mut compile_opts = args.compile_options(
+ config,
+ CompileMode::Build,
+ workspace.as_ref(),
+ ProfileChecking::Checked,
+ )?;
+
+ compile_opts.build_config.requested_profile =
+ args.get_profile_name(config, "release", ProfileChecking::Checked)?;
+
if args.is_present("list") {
ops::install_list(root, config)?;
} else {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/locate_project.rs cargo-0.51.0/src/bin/cargo/commands/locate_project.rs
--- cargo-0.47.0/src/bin/cargo/commands/locate_project.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/locate_project.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,4 +1,6 @@
use crate::command_prelude::*;
+use anyhow::bail;
+use cargo::{drop_println, CargoResult};
use serde::Serialize;
pub fn cli() -> App {
@@ -6,6 +8,15 @@
.about("Print a JSON representation of a Cargo.toml file's location")
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg_manifest_path()
+ .arg(
+ opt(
+ "message-format",
+ "Output representation [possible values: json, plain]",
+ )
+ .value_name("FMT"),
+ )
+ .arg(opt("workspace", "Locate Cargo.toml of the workspace root"))
+ .after_help("Run `cargo help locate-project` for more detailed information.\n")
}
#[derive(Serialize)]
@@ -14,7 +25,18 @@
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
- let root = args.root_manifest(config)?;
+ let root_manifest;
+ let workspace;
+ let root = match WhatToFind::parse(args) {
+ WhatToFind::CurrentManifest => {
+ root_manifest = args.root_manifest(config)?;
+ &root_manifest
+ }
+ WhatToFind::Workspace => {
+ workspace = args.workspace(config)?;
+ workspace.root_manifest()
+ }
+ };
let root = root
.to_str()
@@ -28,6 +50,44 @@
let location = ProjectLocation { root };
- config.shell().print_json(&location);
+ match MessageFormat::parse(args)? {
+ MessageFormat::Json => config.shell().print_json(&location),
+ MessageFormat::Plain => drop_println!(config, "{}", location.root),
+ }
+
Ok(())
}
+
+enum WhatToFind {
+ CurrentManifest,
+ Workspace,
+}
+
+impl WhatToFind {
+ fn parse(args: &ArgMatches<'_>) -> Self {
+ if args.is_present("workspace") {
+ WhatToFind::Workspace
+ } else {
+ WhatToFind::CurrentManifest
+ }
+ }
+}
+
+enum MessageFormat {
+ Json,
+ Plain,
+}
+
+impl MessageFormat {
+ fn parse(args: &ArgMatches<'_>) -> CargoResult {
+ let fmt = match args.value_of("message-format") {
+ Some(fmt) => fmt,
+ None => return Ok(MessageFormat::Json),
+ };
+ match fmt.to_ascii_lowercase().as_str() {
+ "json" => Ok(MessageFormat::Json),
+ "plain" => Ok(MessageFormat::Plain),
+ s => bail!("invalid message format specifier: `{}`", s),
+ }
+ }
+}
diff -Nru cargo-0.47.0/src/bin/cargo/commands/login.rs cargo-0.51.0/src/bin/cargo/commands/login.rs
--- cargo-0.47.0/src/bin/cargo/commands/login.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/login.rs 2021-02-04 15:18:32.000000000 +0000
@@ -16,6 +16,7 @@
.hidden(true),
)
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
+ .after_help("Run `cargo help login` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/logout.rs cargo-0.51.0/src/bin/cargo/commands/logout.rs
--- cargo-0.47.0/src/bin/cargo/commands/logout.rs 1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/logout.rs 2021-02-04 15:18:32.000000000 +0000
@@ -0,0 +1,42 @@
+use crate::command_prelude::*;
+use anyhow::format_err;
+use cargo::core::features;
+use cargo::ops;
+
+pub fn cli() -> App {
+ subcommand("logout")
+ .about("Remove an API token from the registry locally")
+ .arg(opt("quiet", "No output printed to stdout").short("q"))
+ .arg(opt("registry", "Registry to use").value_name("REGISTRY"))
+ .after_help("Run `cargo help logout` for more detailed information.\n")
+}
+
+pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
+ let unstable = config.cli_unstable();
+ if !(unstable.credential_process || unstable.unstable_options) {
+ const SEE: &str = "See https://github.com/rust-lang/cargo/issues/8933 for more \
+ information about the `cargo logout` command.";
+ if features::nightly_features_allowed() {
+ return Err(format_err!(
+ "the `cargo logout` command is unstable, pass `-Z unstable-options` to enable it\n\
+ {}",
+ SEE
+ )
+ .into());
+ } else {
+ return Err(format_err!(
+ "the `cargo logout` command is unstable, and only available on the \
+ nightly channel of Cargo, but this is the `{}` channel\n\
+ {}\n\
+ {}",
+ features::channel(),
+ features::SEE_CHANNELS,
+ SEE
+ )
+ .into());
+ }
+ }
+ config.load_credentials()?;
+ ops::registry_logout(config, args.value_of("registry").map(String::from))?;
+ Ok(())
+}
diff -Nru cargo-0.47.0/src/bin/cargo/commands/metadata.rs cargo-0.51.0/src/bin/cargo/commands/metadata.rs
--- cargo-0.47.0/src/bin/cargo/commands/metadata.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/metadata.rs 2021-02-04 15:18:32.000000000 +0000
@@ -26,6 +26,7 @@
.value_name("VERSION")
.possible_value("1"),
)
+ .after_help("Run `cargo help metadata` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/mod.rs cargo-0.51.0/src/bin/cargo/commands/mod.rs
--- cargo-0.47.0/src/bin/cargo/commands/mod.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/mod.rs 2021-02-04 15:18:32.000000000 +0000
@@ -15,6 +15,7 @@
install::cli(),
locate_project::cli(),
login::cli(),
+ logout::cli(),
metadata::cli(),
new::cli(),
owner::cli(),
@@ -52,6 +53,7 @@
"install" => install::exec,
"locate-project" => locate_project::exec,
"login" => login::exec,
+ "logout" => logout::exec,
"metadata" => metadata::exec,
"new" => new::exec,
"owner" => owner::exec,
@@ -85,10 +87,12 @@
pub mod fix;
pub mod generate_lockfile;
pub mod git_checkout;
+pub mod help;
pub mod init;
pub mod install;
pub mod locate_project;
pub mod login;
+pub mod logout;
pub mod metadata;
pub mod new;
pub mod owner;
diff -Nru cargo-0.47.0/src/bin/cargo/commands/new.rs cargo-0.51.0/src/bin/cargo/commands/new.rs
--- cargo-0.47.0/src/bin/cargo/commands/new.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/new.rs 2021-02-04 15:18:32.000000000 +0000
@@ -9,6 +9,7 @@
.arg(Arg::with_name("path").required(true))
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
.arg_new_opts()
+ .after_help("Run `cargo help new` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/owner.rs cargo-0.51.0/src/bin/cargo/commands/owner.rs
--- cargo-0.47.0/src/bin/cargo/commands/owner.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/owner.rs 2021-02-04 15:18:32.000000000 +0000
@@ -27,15 +27,7 @@
.arg(opt("index", "Registry index to modify owners for").value_name("INDEX"))
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
- .after_help(
- "\
-This command will modify the owners for a crate on the specified registry (or
-default). Owners of a crate can upload new versions and yank old versions.
-Explicitly named owners can also modify the set of owners, so take care!
-
- See https://doc.rust-lang.org/cargo/reference/publishing.html#cargo-owner
- for detailed documentation and troubleshooting.",
- )
+ .after_help("Run `cargo help owner` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/package.rs cargo-0.51.0/src/bin/cargo/commands/package.rs
--- cargo-0.47.0/src/bin/cargo/commands/package.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/package.rs 2021-02-04 15:18:32.000000000 +0000
@@ -30,6 +30,7 @@
.arg_features()
.arg_manifest_path()
.arg_jobs()
+ .after_help("Run `cargo help package` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/pkgid.rs cargo-0.51.0/src/bin/cargo/commands/pkgid.rs
--- cargo-0.47.0/src/bin/cargo/commands/pkgid.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/pkgid.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,6 +1,7 @@
use crate::command_prelude::*;
use cargo::ops;
+use cargo::util::print_available_packages;
pub fn cli() -> App {
subcommand("pkgid")
@@ -9,32 +10,14 @@
.arg(Arg::with_name("spec"))
.arg_package("Argument to get the package ID specifier for")
.arg_manifest_path()
- .after_help(
- "\
-Given a argument, print out the fully qualified package ID specifier.
-This command will generate an error if is ambiguous as to which package
-it refers to in the dependency graph. If no is given, then the pkgid for
-the local package is printed.
-
-This command requires that a lockfile is available and dependencies have been
-fetched.
-
-Example Package IDs
-
- pkgid | name | version | url
- |-----------------------------|--------|-----------|---------------------|
- foo | foo | * | *
- foo:1.2.3 | foo | 1.2.3 | *
- crates.io/foo | foo | * | *://crates.io/foo
- crates.io/foo#1.2.3 | foo | 1.2.3 | *://crates.io/foo
- crates.io/bar#foo:1.2.3 | foo | 1.2.3 | *://crates.io/bar
- https://crates.io/foo#1.2.3 | foo | 1.2.3 | https://crates.io/foo
-",
- )
+ .after_help("Run `cargo help pkgid` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
+ if args.is_present_with_zero_values("package") {
+ print_available_packages(&ws)?
+ }
let spec = args.value_of("spec").or_else(|| args.value_of("package"));
let spec = ops::pkgid(&ws, spec)?;
cargo::drop_println!(config, "{}", spec);
diff -Nru cargo-0.47.0/src/bin/cargo/commands/publish.rs cargo-0.51.0/src/bin/cargo/commands/publish.rs
--- cargo-0.47.0/src/bin/cargo/commands/publish.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/publish.rs 2021-02-04 15:18:32.000000000 +0000
@@ -23,6 +23,7 @@
.arg_jobs()
.arg_dry_run("Perform all checks without uploading")
.arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
+ .after_help("Run `cargo help publish` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/read_manifest.rs cargo-0.51.0/src/bin/cargo/commands/read_manifest.rs
--- cargo-0.47.0/src/bin/cargo/commands/read_manifest.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/read_manifest.rs 2021-02-04 15:18:32.000000000 +0000
@@ -15,6 +15,6 @@
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
- config.shell().print_json(&ws.current()?);
+ config.shell().print_json(&ws.current()?.serialized(config));
Ok(())
}
diff -Nru cargo-0.47.0/src/bin/cargo/commands/run.rs cargo-0.51.0/src/bin/cargo/commands/run.rs
--- cargo-0.47.0/src/bin/cargo/commands/run.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/run.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,7 +1,8 @@
use crate::command_prelude::*;
-
+use crate::util::restricted_names::is_glob_pattern;
+use crate::util::ProcessError;
use cargo::core::Verbosity;
-use cargo::ops::{self, CompileFilter};
+use cargo::ops::{self, CompileFilter, Packages};
pub fn cli() -> App {
subcommand("run")
@@ -25,18 +26,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-If neither `--bin` nor `--example` are given, then if the package only has one
-bin target it will be run. Otherwise `--bin` specifies the bin target to run,
-and `--example` specifies the example target to run. At most one of `--bin` or
-`--example` can be provided.
-
-All the arguments following the two dashes (`--`) are passed to the binary to
-run. If you're passing arguments to both Cargo and the binary, the ones after
-`--` go to the binary, the ones before go to Cargo.
-",
- )
+ .after_help("Run `cargo help run` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
@@ -49,6 +39,17 @@
ProfileChecking::Checked,
)?;
+ // Disallow `spec` to be an glob pattern
+ if let Packages::Packages(opt_in) = &compile_opts.spec {
+ if let Some(pattern) = opt_in.iter().find(|s| is_glob_pattern(s)) {
+ return Err(anyhow::anyhow!(
+ "`cargo run` does not support glob pattern `{}` on package selection",
+ pattern,
+ )
+ .into());
+ }
+ }
+
if !args.is_present("example") && !args.is_present("bin") {
let default_runs: Vec<_> = compile_opts
.spec
@@ -79,26 +80,29 @@
};
}
};
- match ops::run(&ws, &compile_opts, &values_os(args, "args"))? {
- None => Ok(()),
- Some(err) => {
- // If we never actually spawned the process then that sounds pretty
- // bad and we always want to forward that up.
- let exit = match err.exit {
- Some(exit) => exit,
- None => return Err(CliError::new(err.into(), 101)),
- };
- // If `-q` was passed then we suppress extra error information about
- // a failed process, we assume the process itself printed out enough
- // information about why it failed so we don't do so as well
- let exit_code = exit.code().unwrap_or(101);
- let is_quiet = config.shell().verbosity() == Verbosity::Quiet;
- Err(if is_quiet {
- CliError::code(exit_code)
- } else {
- CliError::new(err.into(), exit_code)
- })
+ ops::run(&ws, &compile_opts, &values_os(args, "args")).map_err(|err| {
+ let proc_err = match err.downcast_ref::() {
+ Some(e) => e,
+ None => return CliError::new(err, 101),
+ };
+
+ // If we never actually spawned the process then that sounds pretty
+ // bad and we always want to forward that up.
+ let exit = match proc_err.exit {
+ Some(exit) => exit,
+ None => return CliError::new(err, 101),
+ };
+
+ // If `-q` was passed then we suppress extra error information about
+ // a failed process, we assume the process itself printed out enough
+ // information about why it failed so we don't do so as well
+ let exit_code = exit.code().unwrap_or(101);
+ let is_quiet = config.shell().verbosity() == Verbosity::Quiet;
+ if is_quiet {
+ CliError::code(exit_code)
+ } else {
+ CliError::new(err, exit_code)
}
- }
+ })
}
diff -Nru cargo-0.47.0/src/bin/cargo/commands/rustc.rs cargo-0.51.0/src/bin/cargo/commands/rustc.rs
--- cargo-0.47.0/src/bin/cargo/commands/rustc.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/rustc.rs 2021-02-04 15:18:32.000000000 +0000
@@ -30,22 +30,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-The specified target for the current package (or package specified by SPEC if
-provided) will be compiled along with all of its dependencies. The specified
-... will all be passed to the final compiler invocation, not any of the
-dependencies. Note that the compiler will still unconditionally receive
-arguments such as -L, --extern, and --crate-type, and the specified ...
-will simply be added to the compiler invocation.
-
-This command requires that only one target is being compiled. If more than one
-target is available for the current package the filters of --lib, --bin, etc,
-must be used to select which target is compiled. To pass flags to all compiler
-processes spawned by Cargo, use the $RUSTFLAGS environment variable or the
-`build.rustflags` configuration option.
-",
- )
+ .after_help("Run `cargo help rustc` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/rustdoc.rs cargo-0.51.0/src/bin/cargo/commands/rustdoc.rs
--- cargo-0.47.0/src/bin/cargo/commands/rustdoc.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/rustdoc.rs 2021-02-04 15:18:32.000000000 +0000
@@ -34,21 +34,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-The specified target for the current package (or package specified by SPEC if
-provided) will be documented with the specified `...` being passed to the
-final rustdoc invocation. Dependencies will not be documented as part of this
-command. Note that rustdoc will still unconditionally receive arguments such
-as `-L`, `--extern`, and `--crate-type`, and the specified `...` will
-simply be added to the rustdoc invocation.
-
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package should be documented. If it is not given, then the
-current package is documented. For more information on SPEC and its format, see
-the `cargo help pkgid` command.
-",
- )
+ .after_help("Run `cargo help rustdoc` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/search.rs cargo-0.51.0/src/bin/cargo/commands/search.rs
--- cargo-0.47.0/src/bin/cargo/commands/search.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/search.rs 2021-02-04 15:18:32.000000000 +0000
@@ -18,6 +18,7 @@
.value_name("LIMIT"),
)
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
+ .after_help("Run `cargo help search` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/test.rs cargo-0.51.0/src/bin/cargo/commands/test.rs
--- cargo-0.47.0/src/bin/cargo/commands/test.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/test.rs 2021-02-04 15:18:32.000000000 +0000
@@ -55,48 +55,7 @@
.arg_manifest_path()
.arg_message_format()
.arg_unit_graph()
- .after_help(
- "\
-The test filtering argument TESTNAME and all the arguments following the
-two dashes (`--`) are passed to the test binaries and thus to libtest
-(rustc's built in unit-test and micro-benchmarking framework). If you're
-passing arguments to both Cargo and the binary, the ones after `--` go to the
-binary, the ones before go to Cargo. For details about libtest's arguments see
-the output of `cargo test -- --help`. As an example, this will run all
-tests with `foo` in their name on 3 threads in parallel:
-
- cargo test foo -- --test-threads 3
-
-If the `--package` argument is given, then SPEC is a package ID specification
-which indicates which package should be tested. If it is not given, then the
-current package is tested. For more information on SPEC and its format, see the
-`cargo help pkgid` command.
-
-All packages in the workspace are tested if the `--workspace` flag is supplied. The
-`--workspace` flag is automatically assumed for a virtual manifest.
-Note that `--exclude` has to be specified in conjunction with the `--workspace` flag.
-
-The `--jobs` argument affects the building of the test executable but does
-not affect how many jobs are used when running the tests. The default value
-for the `--jobs` argument is the number of CPUs. If you want to control the
-number of simultaneous running test cases, pass the `--test-threads` option
-to the test binaries:
-
- cargo test -- --test-threads=1
-
-Compilation can be configured via the `test` profile in the manifest.
-
-By default the rust test harness hides output from test execution to
-keep results readable. Test output can be recovered (e.g., for debugging)
-by passing `--nocapture` to the test binaries:
-
- cargo test -- --nocapture
-
-To get the list of all options available for the test binaries use this:
-
- cargo test -- --help
-",
- )
+ .after_help("Run `cargo help test` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/tree.rs cargo-0.51.0/src/bin/cargo/commands/tree.rs
--- cargo-0.47.0/src/bin/cargo/commands/tree.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/tree.rs 2021-02-04 15:18:32.000000000 +0000
@@ -4,6 +4,7 @@
use cargo::core::dependency::DepKind;
use cargo::ops::tree::{self, EdgeKind};
use cargo::ops::Packages;
+use cargo::util::print_available_packages;
use cargo::util::CargoResult;
use std::collections::HashSet;
use std::str::FromStr;
@@ -26,7 +27,8 @@
)
.arg_features()
.arg_target_triple(
- "Filter dependencies matching the given target-triple (default host platform)",
+ "Filter dependencies matching the given target-triple (default host platform). \
+ Pass `all` to include all targets.",
)
.arg(
Arg::with_name("no-dev-dependencies")
@@ -96,6 +98,7 @@
.short("V")
.hidden(true),
)
+ .after_help("Run `cargo help tree` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
@@ -174,6 +177,11 @@
}
let ws = args.workspace(config)?;
+
+ if args.is_present_with_zero_values("package") {
+ print_available_packages(&ws)?;
+ }
+
let charset = tree::Charset::from_str(args.value_of("charset").unwrap())
.map_err(|e| anyhow::anyhow!("{}", e))?;
let opts = tree::TreeOptions {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/uninstall.rs cargo-0.51.0/src/bin/cargo/commands/uninstall.rs
--- cargo-0.47.0/src/bin/cargo/commands/uninstall.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/uninstall.rs 2021-02-04 15:18:32.000000000 +0000
@@ -10,18 +10,20 @@
.arg_package_spec_simple("Package to uninstall")
.arg(multi_opt("bin", "NAME", "Only uninstall the binary NAME"))
.arg(opt("root", "Directory to uninstall packages from").value_name("DIR"))
- .after_help(
- "\
-The argument SPEC is a package ID specification (see `cargo help pkgid`) to
-specify which crate should be uninstalled. By default all binaries are
-uninstalled for a crate but the `--bin` and `--example` flags can be used to
-only uninstall particular binaries.
-",
- )
+ .after_help("Run `cargo help uninstall` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let root = args.value_of("root");
+
+ if args.is_present_with_zero_values("package") {
+ return Err(anyhow::anyhow!(
+ "\"--package \" requires a SPEC format value.\n\
+ Run `cargo help pkgid` for more information about SPEC format."
+ )
+ .into());
+ }
+
let specs = args
.values_of("spec")
.unwrap_or_else(|| args.values_of("package").unwrap_or_default())
diff -Nru cargo-0.47.0/src/bin/cargo/commands/update.rs cargo-0.51.0/src/bin/cargo/commands/update.rs
--- cargo-0.47.0/src/bin/cargo/commands/update.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/update.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,11 +1,13 @@
use crate::command_prelude::*;
use cargo::ops::{self, UpdateOptions};
+use cargo::util::print_available_packages;
pub fn cli() -> App {
subcommand("update")
.about("Update dependencies as recorded in the local lock file")
.arg(opt("quiet", "No output printed to stdout").short("q"))
+ .arg(opt("workspace", "Only update the workspace packages").short("w"))
.arg_package_spec_simple("Package to update")
.arg(opt(
"aggressive",
@@ -14,39 +16,22 @@
.arg_dry_run("Don't actually write the lockfile")
.arg(opt("precise", "Update a single dependency to exactly PRECISE").value_name("PRECISE"))
.arg_manifest_path()
- .after_help(
- "\
-This command requires that a `Cargo.lock` already exists as generated by
-`cargo build` or related commands.
-
-If SPEC is given, then a conservative update of the lockfile will be
-performed. This means that only the dependency specified by SPEC will be
-updated. Its transitive dependencies will be updated only if SPEC cannot be
-updated without updating dependencies. All other dependencies will remain
-locked at their currently recorded versions.
-
-If PRECISE is specified, then `--aggressive` must not also be specified. The
-argument PRECISE is a string representing a precise revision that the package
-being updated should be updated to. For example, if the package comes from a git
-repository, then PRECISE would be the exact revision that the repository should
-be updated to.
-
-If SPEC is not given, then all dependencies will be re-resolved and
-updated.
-
-For more information about package ID specifications, see `cargo help pkgid`.
-",
- )
+ .after_help("Run `cargo help update` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
+ if args.is_present_with_zero_values("package") {
+ print_available_packages(&ws)?;
+ }
+
let update_opts = UpdateOptions {
aggressive: args.is_present("aggressive"),
precise: args.value_of("precise"),
to_update: values(args, "package"),
dry_run: args.is_present("dry-run"),
+ workspace: args.is_present("workspace"),
config,
};
ops::update_lockfile(&ws, &update_opts)?;
diff -Nru cargo-0.47.0/src/bin/cargo/commands/vendor.rs cargo-0.51.0/src/bin/cargo/commands/vendor.rs
--- cargo-0.47.0/src/bin/cargo/commands/vendor.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/vendor.rs 2021-02-04 15:18:32.000000000 +0000
@@ -52,18 +52,7 @@
.long("disallow-duplicates")
.hidden(true),
)
- .after_help(
- "\
-This cargo subcommand will vendor all crates.io and git dependencies for a
-project into the specified directory at ``. After this command completes
-the vendor directory specified by `` will contain all remote sources from
-dependencies specified. Additional manifests beyond the default one can be
-specified with the `-s` option.
-
-The `cargo vendor` command will also print out the configuration necessary
-to use the vendored sources, which you will need to add to `.cargo/config`.
-",
- )
+ .after_help("Run `cargo help vendor` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/verify_project.rs cargo-0.51.0/src/bin/cargo/commands/verify_project.rs
--- cargo-0.47.0/src/bin/cargo/commands/verify_project.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/verify_project.rs 2021-02-04 15:18:32.000000000 +0000
@@ -8,6 +8,7 @@
.about("Check correctness of crate manifest")
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg_manifest_path()
+ .after_help("Run `cargo help verify-project` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/version.rs cargo-0.51.0/src/bin/cargo/commands/version.rs
--- cargo-0.47.0/src/bin/cargo/commands/version.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/version.rs 2021-02-04 15:18:32.000000000 +0000
@@ -5,6 +5,7 @@
subcommand("version")
.about("Show version information")
.arg(opt("quiet", "No output printed to stdout").short("q"))
+ .after_help("Run `cargo help version` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/commands/yank.rs cargo-0.51.0/src/bin/cargo/commands/yank.rs
--- cargo-0.47.0/src/bin/cargo/commands/yank.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/commands/yank.rs 2021-02-04 15:18:32.000000000 +0000
@@ -7,7 +7,11 @@
.about("Remove a pushed crate from the index")
.arg(opt("quiet", "No output printed to stdout").short("q"))
.arg(Arg::with_name("crate"))
- .arg(opt("vers", "The version to yank or un-yank").value_name("VERSION"))
+ .arg(
+ opt("vers", "The version to yank or un-yank")
+ .value_name("VERSION")
+ .required(true),
+ )
.arg(opt(
"undo",
"Undo a yank, putting a version back into the index",
@@ -15,17 +19,7 @@
.arg(opt("index", "Registry index to yank from").value_name("INDEX"))
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
- .after_help(
- "\
-The yank command removes a previously pushed crate's version from the server's
-index. This command does not delete any data, and the crate will still be
-available for download via the registry's download link.
-
-Note that existing crates locked to a yanked version will still be able to
-download the yanked version to use it. Cargo will, however, not allow any new
-crates to be locked to any yanked version.
-",
- )
+ .after_help("Run `cargo help yank` for more detailed information.\n")
}
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
diff -Nru cargo-0.47.0/src/bin/cargo/main.rs cargo-0.51.0/src/bin/cargo/main.rs
--- cargo-0.47.0/src/bin/cargo/main.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/bin/cargo/main.rs 2021-02-04 15:18:32.000000000 +0000
@@ -47,6 +47,21 @@
}
}
+/// Table for defining the aliases which come builtin in `Cargo`.
+/// The contents are structured as: `(alias, aliased_command, description)`.
+const BUILTIN_ALIASES: [(&str, &str, &str); 4] = [
+ ("b", "build", "alias: build"),
+ ("c", "check", "alias: check"),
+ ("r", "run", "alias: run"),
+ ("t", "test", "alias: test"),
+];
+
+/// Function which contains the list of all of the builtin aliases and it's
+/// corresponding execs represented as &str.
+fn builtin_aliases_execs(cmd: &str) -> Option<&(&str, &str, &str)> {
+ BUILTIN_ALIASES.iter().find(|alias| alias.0 == cmd)
+}
+
fn aliased_command(config: &Config, command: &str) -> CargoResult
>> {
let alias_name = format!("alias.{}", command);
let user_alias = match config.get_string(&alias_name) {
@@ -60,12 +75,10 @@
Ok(None) => None,
Err(_) => config.get::
>>(&alias_name)?,
};
- let result = user_alias.or_else(|| match command {
- "b" => Some(vec!["build".to_string()]),
- "c" => Some(vec!["check".to_string()]),
- "r" => Some(vec!["run".to_string()]),
- "t" => Some(vec!["test".to_string()]),
- _ => None,
+
+ let result = user_alias.or_else(|| match builtin_aliases_execs(command) {
+ Some(command_str) => Some(vec![command_str.1.to_string()]),
+ None => None,
});
Ok(result)
}
@@ -106,6 +119,15 @@
});
}
+ // Add the builtin_aliases and them descriptions to the
+ // `commands` `BTreeSet`.
+ for command in &BUILTIN_ALIASES {
+ commands.insert(CommandInfo::BuiltIn {
+ name: command.0.to_string(),
+ about: Some(command.2.to_string()),
+ });
+ }
+
commands
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/build_config.rs cargo-0.51.0/src/cargo/core/compiler/build_config.rs
--- cargo-0.47.0/src/cargo/core/compiler/build_config.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/build_config.rs 2021-02-04 15:18:32.000000000 +0000
@@ -86,10 +86,7 @@
/// Whether or not the *user* wants JSON output. Whether or not rustc
/// actually uses JSON is decided in `add_error_format`.
pub fn emit_json(&self) -> bool {
- match self.message_format {
- MessageFormat::Json { .. } => true,
- _ => false,
- }
+ matches!(self.message_format, MessageFormat::Json { .. })
}
pub fn test(&self) -> bool {
@@ -171,18 +168,12 @@
impl CompileMode {
/// Returns `true` if the unit is being checked.
pub fn is_check(self) -> bool {
- match self {
- CompileMode::Check { .. } => true,
- _ => false,
- }
+ matches!(self, CompileMode::Check { .. })
}
/// Returns `true` if this is generating documentation.
pub fn is_doc(self) -> bool {
- match self {
- CompileMode::Doc { .. } => true,
- _ => false,
- }
+ matches!(self, CompileMode::Doc { .. })
}
/// Returns `true` if this a doc test.
@@ -193,42 +184,25 @@
/// Returns `true` if this is any type of test (test, benchmark, doc test, or
/// check test).
pub fn is_any_test(self) -> bool {
- match self {
+ matches!(
+ self,
CompileMode::Test
- | CompileMode::Bench
- | CompileMode::Check { test: true }
- | CompileMode::Doctest => true,
- _ => false,
- }
+ | CompileMode::Bench
+ | CompileMode::Check { test: true }
+ | CompileMode::Doctest
+ )
}
/// Returns `true` if this is something that passes `--test` to rustc.
pub fn is_rustc_test(self) -> bool {
- match self {
- CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true } => true,
- _ => false,
- }
+ matches!(
+ self,
+ CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true }
+ )
}
/// Returns `true` if this is the *execution* of a `build.rs` script.
pub fn is_run_custom_build(self) -> bool {
self == CompileMode::RunCustomBuild
}
-
- /// List of all modes (currently used by `cargo clean -p` for computing
- /// all possible outputs).
- pub fn all_modes() -> &'static [CompileMode] {
- static ALL: [CompileMode; 9] = [
- CompileMode::Test,
- CompileMode::Build,
- CompileMode::Check { test: true },
- CompileMode::Check { test: false },
- CompileMode::Bench,
- CompileMode::Doc { deps: true },
- CompileMode::Doc { deps: false },
- CompileMode::Doctest,
- CompileMode::RunCustomBuild,
- ];
- &ALL
- }
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/build_context/target_info.rs cargo-0.51.0/src/cargo/core/compiler/build_context/target_info.rs
--- cargo-0.47.0/src/cargo/core/compiler/build_context/target_info.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/build_context/target_info.rs 2021-02-04 15:18:32.000000000 +0000
@@ -40,8 +40,6 @@
pub rustflags: Vec,
/// Extra flags to pass to `rustdoc`, see `env_args`.
pub rustdocflags: Vec,
- /// Remove this when it hits stable (1.45)
- pub supports_embed_bitcode: Option,
}
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -143,13 +141,6 @@
.args(&rustflags)
.env_remove("RUSTC_LOG");
- let mut embed_bitcode_test = process.clone();
- embed_bitcode_test.arg("-Cembed-bitcode");
- let supports_embed_bitcode = match kind {
- CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
- _ => None,
- };
-
if let CompileKind::Target(target) = kind {
process.arg("--target").arg(target.rustc_target());
}
@@ -240,7 +231,6 @@
"RUSTDOCFLAGS",
)?,
cfg,
- supports_embed_bitcode,
})
}
@@ -693,6 +683,17 @@
}
}
+ // This is a hack. The unit_dependency graph builder "pretends" that
+ // `CompileKind::Host` is `CompileKind::Target(host)` if the
+ // `--target` flag is not specified. Since the unit_dependency code
+ // needs access to the target config data, create a copy so that it
+ // can be found. See `rebuild_unit_graph_shared` for why this is done.
+ if requested_kinds.iter().any(CompileKind::is_host) {
+ let ct = CompileTarget::new(&rustc.host)?;
+ target_info.insert(ct, host_info.clone());
+ target_config.insert(ct, host_config.clone());
+ }
+
Ok(RustcTargetData {
rustc,
target_config,
diff -Nru cargo-0.47.0/src/cargo/core/compiler/compilation.rs cargo-0.51.0/src/cargo/core/compiler/compilation.rs
--- cargo-0.47.0/src/cargo/core/compiler/compilation.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/compilation.rs 2021-02-04 15:18:32.000000000 +0000
@@ -346,6 +346,7 @@
// try target.{}.runner
let key = format!("target.{}.runner", target);
+
if let Some(v) = bcx.config.get::
>(&key)? {
let path = v.path.resolve_program(bcx.config);
return Ok(Some((path, v.args)));
diff -Nru cargo-0.47.0/src/cargo/core/compiler/compile_kind.rs cargo-0.51.0/src/cargo/core/compiler/compile_kind.rs
--- cargo-0.47.0/src/cargo/core/compiler/compile_kind.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/compile_kind.rs 2021-02-04 15:18:32.000000000 +0000
@@ -27,10 +27,7 @@
impl CompileKind {
pub fn is_host(&self) -> bool {
- match self {
- CompileKind::Host => true,
- _ => false,
- }
+ matches!(self, CompileKind::Host)
}
pub fn for_target(self, target: &Target) -> CompileKind {
diff -Nru cargo-0.47.0/src/cargo/core/compiler/context/compilation_files.rs cargo-0.51.0/src/cargo/core/compiler/context/compilation_files.rs
--- cargo-0.47.0/src/cargo/core/compiler/context/compilation_files.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/context/compilation_files.rs 2021-02-04 15:18:32.000000000 +0000
@@ -207,11 +207,16 @@
}
}
- /// Returns the root of the build output tree for the host
- pub fn host_root(&self) -> &Path {
+ /// Returns the final artifact path for the host (`/…/target/debug`)
+ pub fn host_dest(&self) -> &Path {
self.host.dest()
}
+ /// Returns the root of the build output tree for the host (`/…/target`)
+ pub fn host_root(&self) -> &Path {
+ self.host.root()
+ }
+
/// Returns the host `deps` directory path.
pub fn host_deps(&self) -> &Path {
self.host.deps()
@@ -519,6 +524,7 @@
// settings like debuginfo and whatnot.
unit.profile.hash(&mut hasher);
unit.mode.hash(&mut hasher);
+ cx.lto[unit].hash(&mut hasher);
// Artifacts compiled for the host should have a different metadata
// piece than those compiled for the target, so make sure we throw in
diff -Nru cargo-0.47.0/src/cargo/core/compiler/context/mod.rs cargo-0.51.0/src/cargo/core/compiler/context/mod.rs
--- cargo-0.47.0/src/cargo/core/compiler/context/mod.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/context/mod.rs 2021-02-04 15:18:32.000000000 +0000
@@ -126,10 +126,10 @@
let mut queue = JobQueue::new(self.bcx);
let mut plan = BuildPlan::new();
let build_plan = self.bcx.build_config.build_plan;
+ self.lto = super::lto::generate(self.bcx)?;
self.prepare_units()?;
self.prepare()?;
custom_build::build_map(&mut self)?;
- super::lto::generate(&mut self)?;
self.check_collistions()?;
for unit in &self.bcx.roots {
@@ -210,7 +210,8 @@
// Collect information for `rustdoc --test`.
if unit.mode.is_doc_test() {
let mut unstable_opts = false;
- let args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
+ let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
+ args.extend(compiler::lto_args(&self, unit));
self.compilation.to_doc_test.push(compilation::Doctest {
unit: unit.clone(),
args,
diff -Nru cargo-0.47.0/src/cargo/core/compiler/crate_type.rs cargo-0.51.0/src/cargo/core/compiler/crate_type.rs
--- cargo-0.47.0/src/cargo/core/compiler/crate_type.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/crate_type.rs 2021-02-04 15:18:32.000000000 +0000
@@ -58,16 +58,13 @@
}
pub fn requires_upstream_objects(&self) -> bool {
- match self {
- // "lib" == "rlib" and is a compilation that doesn't actually
- // require upstream object files to exist, only upstream metadata
- // files. As a result, it doesn't require upstream artifacts
- CrateType::Lib | CrateType::Rlib => false,
+ // "lib" == "rlib" and is a compilation that doesn't actually
+ // require upstream object files to exist, only upstream metadata
+ // files. As a result, it doesn't require upstream artifacts
- // Everything else, however, is some form of "linkable output" or
- // something that requires upstream object files.
- _ => true,
- }
+ !matches!(self, CrateType::Lib | CrateType::Rlib)
+ // Everything else, however, is some form of "linkable output" or
+ // something that requires upstream object files.
}
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/custom_build.rs cargo-0.51.0/src/cargo/core/compiler/custom_build.rs
--- cargo-0.47.0/src/cargo/core/compiler/custom_build.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/custom_build.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,5 +1,5 @@
use super::job::{Freshness, Job, Work};
-use super::{fingerprint, Context, Unit};
+use super::{fingerprint, Context, LinkType, Unit};
use crate::core::compiler::context::Metadata;
use crate::core::compiler::job_queue::JobState;
use crate::core::{profiles::ProfileRoot, PackageId};
@@ -23,7 +23,7 @@
/// Names and link kinds of libraries, suitable for the `-l` flag.
pub library_links: Vec,
/// Linker arguments suitable to be passed to `-C link-arg=`
- pub linker_args: Vec,
+ pub linker_args: Vec<(Option, String)>,
/// Various `--cfg` flags to pass to the compiler.
pub cfgs: Vec,
/// Additional environment variables to run the compiler with.
@@ -128,7 +128,7 @@
output: &BuildOutput,
out_dir: &Path,
package_id: PackageId,
-) {
+) -> CargoResult<()> {
let library_paths = output
.library_paths
.iter()
@@ -144,7 +144,8 @@
out_dir,
}
.to_json_string();
- state.stdout(msg);
+ state.stdout(msg)?;
+ Ok(())
}
fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult {
@@ -272,7 +273,7 @@
let output_file = script_run_dir.join("output");
let err_file = script_run_dir.join("stderr");
let root_output_file = script_run_dir.join("root-output");
- let host_target_root = cx.files().host_root().to_path_buf();
+ let host_target_root = cx.files().host_dest().to_path_buf();
let all = (
id,
pkg_name.clone(),
@@ -289,6 +290,8 @@
paths::create_dir_all(&script_dir)?;
paths::create_dir_all(&script_out_dir)?;
+ let extra_link_arg = cx.bcx.config.cli_unstable().extra_link_arg;
+
// Prepare the unit of "dirty work" which will actually run the custom build
// command.
//
@@ -349,17 +352,17 @@
let output = cmd
.exec_with_streaming(
&mut |stdout| {
- if stdout.starts_with(CARGO_WARNING) {
- warnings_in_case_of_panic.push(stdout[CARGO_WARNING.len()..].to_owned());
+ if let Some(warning) = stdout.strip_prefix(CARGO_WARNING) {
+ warnings_in_case_of_panic.push(warning.to_owned());
}
if extra_verbose {
- state.stdout(format!("{}{}", prefix, stdout));
+ state.stdout(format!("{}{}", prefix, stdout))?;
}
Ok(())
},
&mut |stderr| {
if extra_verbose {
- state.stderr(format!("{}{}", prefix, stderr));
+ state.stderr(format!("{}{}", prefix, stderr))?;
}
Ok(())
},
@@ -392,11 +395,16 @@
paths::set_file_time_no_err(output_file, timestamp);
paths::write(&err_file, &output.stderr)?;
paths::write(&root_output_file, util::path2bytes(&script_out_dir)?)?;
- let parsed_output =
- BuildOutput::parse(&output.stdout, &pkg_name, &script_out_dir, &script_out_dir)?;
+ let parsed_output = BuildOutput::parse(
+ &output.stdout,
+ &pkg_name,
+ &script_out_dir,
+ &script_out_dir,
+ extra_link_arg,
+ )?;
if json_messages {
- emit_build_output(state, &parsed_output, script_out_dir.as_path(), id);
+ emit_build_output(state, &parsed_output, script_out_dir.as_path(), id)?;
}
build_script_outputs
.lock()
@@ -417,11 +425,12 @@
&pkg_name,
&prev_script_out_dir,
&script_out_dir,
+ extra_link_arg,
)?,
};
if json_messages {
- emit_build_output(state, &output, script_out_dir.as_path(), id);
+ emit_build_output(state, &output, script_out_dir.as_path(), id)?;
}
build_script_outputs
@@ -432,7 +441,7 @@
});
let mut job = if cx.bcx.build_config.build_plan {
- Job::new(Work::noop(), Freshness::Dirty)
+ Job::new_dirty(Work::noop())
} else {
fingerprint::prepare_target(cx, unit, false)?
};
@@ -466,6 +475,7 @@
pkg_name: &str,
script_out_dir_when_generated: &Path,
script_out_dir: &Path,
+ extra_link_arg: bool,
) -> CargoResult {
let contents = paths::read_bytes(path)?;
BuildOutput::parse(
@@ -473,6 +483,7 @@
pkg_name,
script_out_dir_when_generated,
script_out_dir,
+ extra_link_arg,
)
}
@@ -483,6 +494,7 @@
pkg_name: &str,
script_out_dir_when_generated: &Path,
script_out_dir: &Path,
+ extra_link_arg: bool,
) -> CargoResult {
let mut library_paths = Vec::new();
let mut library_links = Vec::new();
@@ -535,7 +547,23 @@
}
"rustc-link-lib" => library_links.push(value.to_string()),
"rustc-link-search" => library_paths.push(PathBuf::from(value)),
- "rustc-cdylib-link-arg" => linker_args.push(value.to_string()),
+ "rustc-link-arg-cdylib" | "rustc-cdylib-link-arg" => {
+ linker_args.push((Some(LinkType::Cdylib), value))
+ }
+ "rustc-link-arg-bins" => {
+ if extra_link_arg {
+ linker_args.push((Some(LinkType::Bin), value));
+ } else {
+ warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
+ }
+ }
+ "rustc-link-arg" => {
+ if extra_link_arg {
+ linker_args.push((None, value));
+ } else {
+ warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
+ }
+ }
"rustc-cfg" => cfgs.push(value.to_string()),
"rustc-env" => env.push(BuildOutput::parse_rustc_env(&value, &whence)?),
"warning" => warnings.push(value.to_string()),
@@ -784,12 +812,15 @@
.and_then(|bytes| util::bytes2path(&bytes))
.unwrap_or_else(|_| script_out_dir.clone());
+ let extra_link_arg = cx.bcx.config.cli_unstable().extra_link_arg;
+
(
BuildOutput::parse_file(
&output_file,
&unit.pkg.to_string(),
&prev_script_out_dir,
&script_out_dir,
+ extra_link_arg,
)
.ok(),
prev_script_out_dir,
diff -Nru cargo-0.47.0/src/cargo/core/compiler/fingerprint.rs cargo-0.51.0/src/cargo/core/compiler/fingerprint.rs
--- cargo-0.47.0/src/cargo/core/compiler/fingerprint.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/fingerprint.rs 2021-02-04 15:18:32.000000000 +0000
@@ -72,7 +72,7 @@
//! -C incremental=… flag | ✓ |
//! mtime of sources | ✓[^3] |
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
-//! LTO flags | ✓ |
+//! LTO flags | ✓ | ✓
//! config settings[^5] | ✓ |
//! is_std | | ✓
//!
@@ -313,6 +313,7 @@
//!
use std::collections::hash_map::{Entry, HashMap};
+use std::convert::TryInto;
use std::env;
use std::hash::{self, Hasher};
use std::path::{Path, PathBuf};
@@ -336,10 +337,7 @@
use crate::util::{internal, profile, ProcessBuilder};
use super::custom_build::BuildDeps;
-use super::job::{
- Freshness::{Dirty, Fresh},
- Job, Work,
-};
+use super::job::{Job, Work};
use super::{BuildContext, Context, FileFlavor, Unit};
/// Determines if a `unit` is up-to-date, and if not prepares necessary work to
@@ -395,7 +393,7 @@
}
if compare.is_ok() && !force {
- return Ok(Job::new(Work::noop(), Fresh));
+ return Ok(Job::new_fresh());
}
// Clear out the old fingerprint file if it exists. This protects when
@@ -468,7 +466,7 @@
Work::new(move |_| write_fingerprint(&loc, &fingerprint))
};
- Ok(Job::new(write_fingerprint, Dirty))
+ Ok(Job::new_dirty(write_fingerprint))
}
/// Dependency edge information for fingerprints. This is generated for each
@@ -1702,7 +1700,7 @@
let path_mtime = match mtime_cache.entry(path.to_path_buf()) {
Entry::Occupied(o) => *o.get(),
Entry::Vacant(v) => {
- let mtime = match paths::mtime(path) {
+ let mtime = match paths::mtime_recursive(path) {
Ok(mtime) => mtime,
Err(..) => return Some(StaleItem::MissingFile(path.to_path_buf())),
};
@@ -1906,12 +1904,7 @@
fn read_usize(bytes: &mut &[u8]) -> Option {
let ret = bytes.get(..4)?;
*bytes = &bytes[4..];
- Some(
- ((ret[0] as usize) << 0)
- | ((ret[1] as usize) << 8)
- | ((ret[2] as usize) << 16)
- | ((ret[3] as usize) << 24),
- )
+ Some(u32::from_le_bytes(ret.try_into().unwrap()) as usize)
}
fn read_u8(bytes: &mut &[u8]) -> Option {
@@ -1960,10 +1953,7 @@
}
fn write_usize(dst: &mut Vec, val: usize) {
- dst.push(val as u8);
- dst.push((val >> 8) as u8);
- dst.push((val >> 16) as u8);
- dst.push((val >> 24) as u8);
+ dst.extend(&u32::to_le_bytes(val as u32));
}
}
}
@@ -1975,9 +1965,7 @@
let mut found_deps = false;
for line in contents.lines() {
- let env_dep_prefix = "# env-dep:";
- if line.starts_with(env_dep_prefix) {
- let rest = &line[env_dep_prefix.len()..];
+ if let Some(rest) = line.strip_prefix("# env-dep:") {
let mut parts = rest.splitn(2, '=');
let env_var = match parts.next() {
Some(s) => s,
diff -Nru cargo-0.47.0/src/cargo/core/compiler/job_queue.rs cargo-0.51.0/src/cargo/core/compiler/job_queue.rs
--- cargo-0.47.0/src/cargo/core/compiler/job_queue.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/job_queue.rs 2021-02-04 15:18:32.000000000 +0000
@@ -53,7 +53,6 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use std::io;
use std::marker;
-use std::mem;
use std::sync::Arc;
use std::time::Duration;
@@ -163,10 +162,30 @@
}
}
+/// A `JobState` is constructed by `JobQueue::run` and passed to `Job::run`. It includes everything
+/// necessary to communicate between the main thread and the execution of the job.
+///
+/// The job may execute on either a dedicated thread or the main thread. If the job executes on the
+/// main thread, the `output` field must be set to prevent a deadlock.
pub struct JobState<'a> {
/// Channel back to the main thread to coordinate messages and such.
+ ///
+ /// When the `output` field is `Some`, care must be taken to avoid calling `push_bounded` on
+ /// the message queue to prevent a deadlock.
messages: Arc>,
+ /// Normally output is sent to the job queue with backpressure. When the job is fresh
+ /// however we need to immediately display the output to prevent a deadlock as the
+ /// output messages are processed on the same thread as they are sent from. `output`
+ /// defines where to output in this case.
+ ///
+ /// Currently the `Shell` inside `Config` is wrapped in a `RefCell` and thus can't be passed
+ /// between threads. This means that it isn't possible for multiple output messages to be
+ /// interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case
+ /// interleaving is still prevented as the lock would be held for the whole printing of an
+ /// output message.
+ output: Option<&'a Config>,
+
/// The job id that this state is associated with, used when sending
/// messages back to the main thread.
id: JobId,
@@ -232,12 +251,24 @@
.push(Message::BuildPlanMsg(module_name, cmd, filenames));
}
- pub fn stdout(&self, stdout: String) {
- self.messages.push_bounded(Message::Stdout(stdout));
+ pub fn stdout(&self, stdout: String) -> CargoResult<()> {
+ if let Some(config) = self.output {
+ writeln!(config.shell().out(), "{}", stdout)?;
+ } else {
+ self.messages.push_bounded(Message::Stdout(stdout));
+ }
+ Ok(())
}
- pub fn stderr(&self, stderr: String) {
- self.messages.push_bounded(Message::Stderr(stderr));
+ pub fn stderr(&self, stderr: String) -> CargoResult<()> {
+ if let Some(config) = self.output {
+ let mut shell = config.shell();
+ shell.print_ansi(stderr.as_bytes())?;
+ shell.err().write_all(b"\n")?;
+ } else {
+ self.messages.push_bounded(Message::Stderr(stderr));
+ }
+ Ok(())
}
/// A method used to signal to the coordinator thread that the rmeta file
@@ -339,7 +370,11 @@
}
}
- self.queue.queue(unit.clone(), job, queue_deps);
+ // For now we use a fixed placeholder value for the cost of each unit, but
+ // in the future this could be used to allow users to provide hints about
+ // relative expected costs of units, or this could be automatically set in
+ // a smarter way using timing data from a previous compilation.
+ self.queue.queue(unit.clone(), job, queue_deps, 100);
*self.counts.entry(unit.pkg.package_id()).or_insert(0) += 1;
Ok(())
}
@@ -827,20 +862,13 @@
self.note_working_on(cx.bcx.config, unit, fresh)?;
}
- let doit = move || {
- let state = JobState {
- id,
- messages: messages.clone(),
- rmeta_required: Cell::new(rmeta_required),
- _marker: marker::PhantomData,
- };
-
+ let doit = move |state: JobState<'_>| {
let mut sender = FinishOnDrop {
- messages: &messages,
+ messages: &state.messages,
id,
- result: Err(format_err!("worker panicked")),
+ result: None,
};
- sender.result = job.run(&state);
+ sender.result = Some(job.run(&state));
// If the `rmeta_required` wasn't consumed but it was set
// previously, then we either have:
@@ -854,8 +882,10 @@
// we'll just naturally abort the compilation operation but for 1
// we need to make sure that the metadata is flagged as produced so
// send a synthetic message here.
- if state.rmeta_required.get() && sender.result.is_ok() {
- messages.push(Message::Finish(id, Artifact::Metadata, Ok(())));
+ if state.rmeta_required.get() && sender.result.as_ref().unwrap().is_ok() {
+ state
+ .messages
+ .push(Message::Finish(state.id, Artifact::Metadata, Ok(())));
}
// Use a helper struct with a `Drop` implementation to guarantee
@@ -865,23 +895,47 @@
struct FinishOnDrop<'a> {
messages: &'a Queue,
id: JobId,
- result: CargoResult<()>,
+ result: Option>,
}
impl Drop for FinishOnDrop<'_> {
fn drop(&mut self) {
- let msg = mem::replace(&mut self.result, Ok(()));
+ let result = self
+ .result
+ .take()
+ .unwrap_or_else(|| Err(format_err!("worker panicked")));
self.messages
- .push(Message::Finish(self.id, Artifact::All, msg));
+ .push(Message::Finish(self.id, Artifact::All, result));
}
}
};
match fresh {
- Freshness::Fresh => self.timings.add_fresh(),
- Freshness::Dirty => self.timings.add_dirty(),
+ Freshness::Fresh => {
+ self.timings.add_fresh();
+ // Running a fresh job on the same thread is often much faster than spawning a new
+ // thread to run the job.
+ doit(JobState {
+ id,
+ messages: messages.clone(),
+ output: Some(cx.bcx.config),
+ rmeta_required: Cell::new(rmeta_required),
+ _marker: marker::PhantomData,
+ });
+ }
+ Freshness::Dirty => {
+ self.timings.add_dirty();
+ scope.spawn(move |_| {
+ doit(JobState {
+ id,
+ messages: messages.clone(),
+ output: None,
+ rmeta_required: Cell::new(rmeta_required),
+ _marker: marker::PhantomData,
+ })
+ });
+ }
}
- scope.spawn(move |_| doit());
Ok(())
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/job.rs cargo-0.51.0/src/cargo/core/compiler/job.rs
--- cargo-0.47.0/src/cargo/core/compiler/job.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/job.rs 2021-02-04 15:18:32.000000000 +0000
@@ -40,9 +40,20 @@
}
impl Job {
+ /// Creates a new job that does nothing.
+ pub fn new_fresh() -> Job {
+ Job {
+ work: Work::noop(),
+ fresh: Freshness::Fresh,
+ }
+ }
+
/// Creates a new job representing a unit of work.
- pub fn new(work: Work, fresh: Freshness) -> Job {
- Job { work, fresh }
+ pub fn new_dirty(work: Work) -> Job {
+ Job {
+ work,
+ fresh: Freshness::Dirty,
+ }
}
/// Consumes this job by running it, returning the result of the
diff -Nru cargo-0.47.0/src/cargo/core/compiler/lto.rs cargo-0.51.0/src/cargo/core/compiler/lto.rs
--- cargo-0.47.0/src/cargo/core/compiler/lto.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/lto.rs 2021-02-04 15:18:32.000000000 +0000
@@ -1,4 +1,4 @@
-use crate::core::compiler::{CompileMode, Context, CrateType, Unit};
+use crate::core::compiler::{BuildContext, CompileMode, CrateType, Unit};
use crate::core::profiles;
use crate::util::interning::InternedString;
@@ -40,9 +40,9 @@
OnlyObject,
}
-pub fn generate(cx: &mut Context<'_, '_>) -> CargoResult<()> {
+pub fn generate(bcx: &BuildContext<'_, '_>) -> CargoResult> {
let mut map = HashMap::new();
- for unit in cx.bcx.roots.iter() {
+ for unit in bcx.roots.iter() {
let root_lto = match unit.profile.lto {
// LTO not requested, no need for bitcode.
profiles::Lto::Bool(false) | profiles::Lto::Off => Lto::OnlyObject,
@@ -60,10 +60,9 @@
}
}
};
- calculate(cx, &mut map, unit, root_lto)?;
+ calculate(bcx, &mut map, unit, root_lto)?;
}
- cx.lto = map;
- Ok(())
+ Ok(map)
}
/// Whether or not any of these crate types need object code.
@@ -73,21 +72,21 @@
/// Lto setting to use when this unit needs object code.
fn lto_when_needs_object(crate_types: &[CrateType]) -> Lto {
- if crate_types.iter().any(CrateType::can_lto) {
- // A mixed rlib/cdylib whose parent is running LTO. This
- // needs both, for bitcode in the rlib (for LTO) and the
- // cdylib requires object code.
- Lto::ObjectAndBitcode
- } else {
+ if crate_types.iter().all(|ct| *ct == CrateType::Dylib) {
// A dylib whose parent is running LTO. rustc currently
// doesn't support LTO with dylibs, so bitcode is not
// needed.
Lto::OnlyObject
+ } else {
+ // Mixed rlib with a dylib or cdylib whose parent is running LTO. This
+ // needs both: bitcode for the rlib (for LTO) and object code for the
+ // dylib.
+ Lto::ObjectAndBitcode
}
}
fn calculate(
- cx: &Context<'_, '_>,
+ bcx: &BuildContext<'_, '_>,
map: &mut HashMap,
unit: &Unit,
parent_lto: Lto,
@@ -185,8 +184,8 @@
}
};
- for dep in cx.unit_deps(unit) {
- calculate(cx, map, &dep.unit, merged_lto)?;
+ for dep in &bcx.unit_graph[unit] {
+ calculate(bcx, map, &dep.unit, merged_lto)?;
}
Ok(())
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/mod.rs cargo-0.51.0/src/cargo/core/compiler/mod.rs
--- cargo-0.47.0/src/cargo/core/compiler/mod.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/mod.rs 2021-02-04 15:18:32.000000000 +0000
@@ -47,6 +47,7 @@
use self::output_depinfo::output_depinfo;
use self::unit_graph::UnitDep;
pub use crate::core::compiler::unit::{Unit, UnitInterner};
+use crate::core::features::nightly_features_allowed;
use crate::core::manifest::TargetSourcePath;
use crate::core::profiles::{PanicStrategy, Profile, Strip};
use crate::core::{Edition, Feature, PackageId, Target};
@@ -58,6 +59,33 @@
const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";
+#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq)]
+pub enum LinkType {
+ Cdylib,
+ Bin,
+ Test,
+ Bench,
+ Example,
+}
+
+impl From<&super::Target> for Option {
+ fn from(value: &super::Target) -> Self {
+ if value.is_cdylib() {
+ Some(LinkType::Cdylib)
+ } else if value.is_bin() {
+ Some(LinkType::Bin)
+ } else if value.is_test() {
+ Some(LinkType::Test)
+ } else if value.is_bench() {
+ Some(LinkType::Bench)
+ } else if value.is_exe_example() {
+ Some(LinkType::Example)
+ } else {
+ None
+ }
+ }
+}
+
/// A glorified callback for executing calls to rustc. Rather than calling rustc
/// directly, we'll use an `Executor`, giving clients an opportunity to intercept
/// the build calls.
@@ -129,9 +157,9 @@
custom_build::prepare(cx, unit)?
} else if unit.mode.is_doc_test() {
// We run these targets later, so this is just a no-op for now.
- Job::new(Work::noop(), Freshness::Fresh)
+ Job::new_fresh()
} else if build_plan {
- Job::new(rustc(cx, unit, &exec.clone())?, Freshness::Dirty)
+ Job::new_dirty(rustc(cx, unit, &exec.clone())?)
} else {
let force = exec.force_rebuild(unit) || force_rebuild;
let mut job = fingerprint::prepare_target(cx, unit, force)?;
@@ -195,7 +223,7 @@
// If we are a binary and the package also contains a library, then we
// don't pass the `-l` flags.
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
- let pass_cdylib_link_args = unit.target.is_cdylib();
+ let link_type = (&unit.target).into();
let dep_info_name = match cx.files().metadata(unit) {
Some(metadata) => format!("{}-{}.d", unit.target.crate_name(), metadata),
@@ -206,7 +234,7 @@
rustc.args(cx.bcx.rustflags_args(unit));
if cx.bcx.config.cli_unstable().binary_dep_depinfo {
- rustc.arg("-Zbinary-dep-depinfo");
+ rustc.arg("-Z").arg("binary-dep-depinfo");
}
let mut output_options = OutputOptions::new(cx, unit);
let package_id = unit.pkg.package_id();
@@ -216,7 +244,7 @@
exec.init(cx, unit);
let exec = exec.clone();
- let root_output = cx.files().host_root().to_path_buf();
+ let root_output = cx.files().host_dest().to_path_buf();
let target_dir = cx.bcx.ws.target_dir().into_path_unlocked();
let pkg_root = unit.pkg.root().to_path_buf();
let cwd = rustc
@@ -243,7 +271,7 @@
&script_outputs,
&build_scripts,
pass_l_flag,
- pass_cdylib_link_args,
+ link_type,
current_id,
)?;
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
@@ -290,7 +318,7 @@
&mut |line| on_stderr_line(state, line, package_id, &target, &mut output_options),
)
.map_err(verbose_if_simple_exit_code)
- .chain_err(|| format!("could not compile `{}`.", name))?;
+ .chain_err(|| format!("could not compile `{}`", name))?;
}
if rustc_dep_info_loc.exists() {
@@ -325,7 +353,7 @@
build_script_outputs: &BuildScriptOutputs,
build_scripts: &BuildScripts,
pass_l_flag: bool,
- pass_cdylib_link_args: bool,
+ link_type: Option,
current_id: PackageId,
) -> CargoResult<()> {
for key in build_scripts.to_link.iter() {
@@ -338,6 +366,7 @@
for path in output.library_paths.iter() {
rustc.arg("-L").arg(path);
}
+
if key.0 == current_id {
for cfg in &output.cfgs {
rustc.arg("--cfg").arg(cfg);
@@ -347,10 +376,12 @@
rustc.arg("-l").arg(name);
}
}
- if pass_cdylib_link_args {
- for arg in output.linker_args.iter() {
- let link_arg = format!("link-arg={}", arg);
- rustc.arg("-C").arg(link_arg);
+ }
+
+ if link_type.is_some() {
+ for (lt, arg) in &output.linker_args {
+ if lt.is_none() || *lt == link_type {
+ rustc.arg("-C").arg(format!("link-arg={}", arg));
}
}
}
@@ -447,7 +478,7 @@
fresh,
}
.to_json_string();
- state.stdout(msg);
+ state.stdout(msg)?;
}
Ok(())
}))
@@ -529,10 +560,15 @@
let mut base = cx
.compilation
.rustc_process(unit, is_primary, is_workspace)?;
+
+ if is_primary {
+ base.env("CARGO_PRIMARY_PACKAGE", "1");
+ }
+
if cx.bcx.config.cli_unstable().jobserver_per_rustc {
let client = cx.new_jobserver()?;
base.inherit_jobserver(&client);
- base.arg("-Zjobserver-token-requests");
+ base.arg("-Z").arg("jobserver-token-requests");
assert!(cx.rustc_clients.insert(unit.clone(), client).is_none());
} else {
base.inherit_jobserver(&cx.jobserver);
@@ -578,7 +614,9 @@
rustdoc.args(bcx.rustdocflags_args(unit));
- add_crate_versions_if_requested(bcx, unit, &mut rustdoc);
+ if !crate_version_flag_already_present(&rustdoc) {
+ append_crate_version_flag(unit, &mut rustdoc);
+ }
let name = unit.pkg.name().to_string();
let build_script_outputs = Arc::clone(&cx.build_script_outputs);
@@ -611,21 +649,11 @@
&mut |line| on_stderr_line(state, line, package_id, &target, &mut output_options),
false,
)
- .chain_err(|| format!("Could not document `{}`.", name))?;
+ .chain_err(|| format!("could not document `{}`", name))?;
Ok(())
}))
}
-fn add_crate_versions_if_requested(
- bcx: &BuildContext<'_, '_>,
- unit: &Unit,
- rustdoc: &mut ProcessBuilder,
-) {
- if bcx.config.cli_unstable().crate_versions && !crate_version_flag_already_present(rustdoc) {
- append_crate_version_flag(unit, rustdoc);
- }
-}
-
// The --crate-version flag could have already been passed in RUSTDOCFLAGS
// or as an extra compiler argument for rustdoc
fn crate_version_flag_already_present(rustdoc: &ProcessBuilder) -> bool {
@@ -709,6 +737,7 @@
// to emit a message that cargo will intercept.
json.push_str(",artifacts");
}
+
match cx.bcx.build_config.message_format {
MessageFormat::Short | MessageFormat::Json { short: true, .. } => {
json.push_str(",diagnostic-short");
@@ -716,6 +745,26 @@
_ => {}
}
cmd.arg(json);
+
+ if nightly_features_allowed() {
+ let config = cx.bcx.config;
+ match (
+ config.cli_unstable().terminal_width,
+ config.shell().err_width().diagnostic_terminal_width(),
+ ) {
+ // Terminal width explicitly provided - only useful for testing.
+ (Some(Some(width)), _) => {
+ cmd.arg(format!("-Zterminal-width={}", width));
+ }
+ // Terminal width was not explicitly provided but flag was provided - common case.
+ (Some(None), Some(width)) => {
+ cmd.arg(format!("-Zterminal-width={}", width));
+ }
+ // User didn't opt-in.
+ _ => (),
+ }
+ }
+
Ok(())
}
@@ -783,49 +832,9 @@
cmd.arg("-C").arg(format!("panic={}", panic));
}
- match cx.lto[unit] {
- lto::Lto::Run(None) => {
- cmd.arg("-C").arg("lto");
- }
- lto::Lto::Run(Some(s)) => {
- cmd.arg("-C").arg(format!("lto={}", s));
- }
- lto::Lto::Off => {
- cmd.arg("-C").arg("lto=off");
- }
- lto::Lto::ObjectAndBitcode => {} // this is rustc's default
- lto::Lto::OnlyBitcode => {
- // Note that this compiler flag, like the one below, is just an
- // optimization in terms of build time. If we don't pass it then
- // both object code and bitcode will show up. This is lagely just
- // compat until the feature lands on stable and we can remove the
- // conditional branch.
- if cx
- .bcx
- .target_data
- .info(CompileKind::Host)
- .supports_embed_bitcode
- .unwrap()
- {
- cmd.arg("-Clinker-plugin-lto");
- }
- }
- lto::Lto::OnlyObject => {
- if cx
- .bcx
- .target_data
- .info(CompileKind::Host)
- .supports_embed_bitcode
- .unwrap()
- {
- cmd.arg("-Cembed-bitcode=no");
- }
- }
- }
+ cmd.args(<o_args(cx, unit));
if let Some(n) = codegen_units {
- // There are some restrictions with LTO and codegen-units, so we
- // only add codegen units when LTO is not used.
cmd.arg("-C").arg(&format!("codegen-units={}", n));
}
@@ -869,7 +878,7 @@
// will simply not be needed when the behavior is stabilized in the Rust
// compiler itself.
if *panic == PanicStrategy::Abort {
- cmd.arg("-Zpanic-abort-tests");
+ cmd.arg("-Z").arg("panic-abort-tests");
}
} else if test {
cmd.arg("--cfg").arg("test");
@@ -929,7 +938,8 @@
// any non-public crate in the sysroot).
//
// RUSTC_BOOTSTRAP allows unstable features on stable.
- cmd.arg("-Zforce-unstable-if-unmarked")
+ cmd.arg("-Z")
+ .arg("force-unstable-if-unmarked")
.env("RUSTC_BOOTSTRAP", "1");
}
@@ -952,6 +962,23 @@
Ok(())
}
+fn lto_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec {
+ let mut result = Vec::new();
+ let mut push = |arg: &str| {
+ result.push(OsString::from("-C"));
+ result.push(OsString::from(arg));
+ };
+ match cx.lto[unit] {
+ lto::Lto::Run(None) => push("lto"),
+ lto::Lto::Run(Some(s)) => push(&format!("lto={}", s)),
+ lto::Lto::Off => push("lto=off"),
+ lto::Lto::ObjectAndBitcode => {} // this is rustc's default
+ lto::Lto::OnlyBitcode => push("linker-plugin-lto"),
+ lto::Lto::OnlyObject => push("embed-bitcode=no"),
+ }
+ result
+}
+
fn build_deps_args(
cmd: &mut ProcessBuilder,
cx: &mut Context<'_, '_>,
@@ -1037,7 +1064,7 @@
if unit
.pkg
.manifest()
- .features()
+ .unstable_features()
.require(Feature::public_dependency())
.is_ok()
&& !dep.public
@@ -1142,7 +1169,7 @@
_package_id: PackageId,
_target: &Target,
) -> CargoResult<()> {
- state.stdout(line.to_string());
+ state.stdout(line.to_string())?;
Ok(())
}
@@ -1180,7 +1207,7 @@
// something like that), so skip over everything that doesn't look like a
// JSON message.
if !line.starts_with('{') {
- state.stderr(line.to_string());
+ state.stderr(line.to_string())?;
return Ok(true);
}
@@ -1192,7 +1219,7 @@
// to stderr.
Err(e) => {
debug!("failed to parse json: {:?}", e);
- state.stderr(line.to_string());
+ state.stderr(line.to_string())?;
return Ok(true);
}
};
@@ -1228,7 +1255,7 @@
.map(|v| String::from_utf8(v).expect("utf8"))
.expect("strip should never fail")
};
- state.stderr(rendered);
+ state.stderr(rendered)?;
return Ok(true);
}
}
@@ -1319,7 +1346,7 @@
// Switch json lines from rustc/rustdoc that appear on stderr to stdout
// instead. We want the stdout of Cargo to always be machine parseable as
// stderr has our colorized human-readable messages.
- state.stdout(msg);
+ state.stdout(msg)?;
Ok(true)
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/rustdoc.rs cargo-0.51.0/src/cargo/core/compiler/rustdoc.rs
--- cargo-0.47.0/src/cargo/core/compiler/rustdoc.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/rustdoc.rs 2021-02-04 15:18:32.000000000 +0000
@@ -16,7 +16,7 @@
pub enum RustdocExternMode {
/// Use a local `file://` URL.
Local,
- /// Use a remote URL to https://doc.rust-lang.org/ (default).
+ /// Use a remote URL to (default).
Remote,
/// An arbitrary URL.
Url(String),
@@ -53,11 +53,35 @@
}
#[derive(serde::Deserialize, Debug)]
+#[serde(default)]
pub struct RustdocExternMap {
- registries: HashMap,
+ #[serde(deserialize_with = "default_crates_io_to_docs_rs")]
+ pub(crate) registries: HashMap,
std: Option,
}
+impl Default for RustdocExternMap {
+ fn default() -> Self {
+ let mut registries = HashMap::new();
+ registries.insert("crates-io".into(), "https://docs.rs/".into());
+ Self {
+ registries,
+ std: None,
+ }
+ }
+}
+
+fn default_crates_io_to_docs_rs<'de, D: serde::Deserializer<'de>>(
+ de: D,
+) -> Result, D::Error> {
+ use serde::Deserialize;
+ let mut registries = HashMap::deserialize(de)?;
+ if !registries.contains_key("crates-io") {
+ registries.insert("crates-io".into(), "https://docs.rs/".into());
+ }
+ Ok(registries)
+}
+
impl hash::Hash for RustdocExternMap {
fn hash(&self, into: &mut H) {
self.std.hash(into);
@@ -79,10 +103,6 @@
return Ok(());
}
let map = config.doc_extern_map()?;
- if map.registries.is_empty() && map.std.is_none() {
- // Skip doing unnecessary work.
- return Ok(());
- }
let mut unstable_opts = false;
// Collect mapping of registry name -> index url.
let name2url: HashMap<&String, Url> = map
diff -Nru cargo-0.47.0/src/cargo/core/compiler/standard_lib.rs cargo-0.51.0/src/cargo/core/compiler/standard_lib.rs
--- cargo-0.47.0/src/cargo/core/compiler/standard_lib.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/standard_lib.rs 2021-02-04 15:18:32.000000000 +0000
@@ -3,7 +3,7 @@
use crate::core::compiler::UnitInterner;
use crate::core::compiler::{CompileKind, CompileMode, RustcTargetData, Unit};
use crate::core::profiles::{Profiles, UnitFor};
-use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
+use crate::core::resolver::features::{FeaturesFor, RequestedFeatures, ResolvedFeatures};
use crate::core::resolver::{HasDevUnits, ResolveOpts};
use crate::core::{Dependency, PackageId, PackageSet, Resolve, SourceId, Workspace};
use crate::ops::{self, Packages};
@@ -46,7 +46,7 @@
let patches = to_patch
.iter()
.map(|&name| {
- let source_path = SourceId::for_path(&src_path.join("src").join("tools").join(name))?;
+ let source_path = SourceId::for_path(&src_path.join("library").join(name))?;
let dep = Dependency::parse_no_deprecated(name, None, source_path)?;
Ok(dep)
})
@@ -55,10 +55,10 @@
let mut patch = HashMap::new();
patch.insert(crates_io_url, patches);
let members = vec![
- String::from("src/libstd"),
- String::from("src/libcore"),
- String::from("src/liballoc"),
- String::from("src/libtest"),
+ String::from("library/std"),
+ String::from("library/core"),
+ String::from("library/alloc"),
+ String::from("library/test"),
];
let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
&src_path,
@@ -85,7 +85,7 @@
// other crates need to alter their features, this should be fine, for
// now. Perhaps in the future features will be decoupled from the resolver
// and it will be easier to control feature selection.
- let current_manifest = src_path.join("src/libtest/Cargo.toml");
+ let current_manifest = src_path.join("library/test/Cargo.toml");
// TODO: Consider doing something to enforce --locked? Or to prevent the
// lock file from being written, such as setting ephemeral.
let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, config)?;
@@ -99,11 +99,20 @@
spec_pkgs.push("test".to_string());
let spec = Packages::Packages(spec_pkgs);
let specs = spec.to_package_id_specs(&std_ws)?;
- let features = vec!["panic-unwind".to_string(), "backtrace".to_string()];
+ let features = match &config.cli_unstable().build_std_features {
+ Some(list) => list.clone(),
+ None => vec![
+ "panic-unwind".to_string(),
+ "backtrace".to_string(),
+ "default".to_string(),
+ ],
+ };
// dev_deps setting shouldn't really matter here.
let opts = ResolveOpts::new(
- /*dev_deps*/ false, &features, /*all_features*/ false,
- /*uses_default_features*/ true,
+ /*dev_deps*/ false,
+ RequestedFeatures::from_command_line(
+ &features, /*all_features*/ false, /*uses_default_features*/ false,
+ ),
);
let resolve = ops::resolve_ws_with_opts(
&std_ws,
@@ -172,6 +181,7 @@
mode,
features.clone(),
/*is_std*/ true,
+ /*dep_hash*/ 0,
));
}
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/timings.rs cargo-0.51.0/src/cargo/core/compiler/timings.rs
--- cargo-0.47.0/src/cargo/core/compiler/timings.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/timings.rs 2021-02-04 15:18:32.000000000 +0000
@@ -179,7 +179,7 @@
let unit_time = UnitTime {
unit,
target,
- start: d_as_f64(self.start.elapsed()),
+ start: self.start.elapsed().as_secs_f64(),
duration: 0.0,
rmeta_time: None,
unlocked_units: Vec::new(),
@@ -200,7 +200,7 @@
Some(ut) => ut,
None => return,
};
- let t = d_as_f64(self.start.elapsed());
+ let t = self.start.elapsed().as_secs_f64();
unit_time.rmeta_time = Some(t - unit_time.start);
assert!(unit_time.unlocked_rmeta_units.is_empty());
unit_time
@@ -218,7 +218,7 @@
Some(ut) => ut,
None => return,
};
- let t = d_as_f64(self.start.elapsed());
+ let t = self.start.elapsed().as_secs_f64();
unit_time.duration = t - unit_time.start;
assert!(unit_time.unlocked_units.is_empty());
unit_time
@@ -262,7 +262,7 @@
return;
}
let c = Concurrency {
- t: d_as_f64(self.start.elapsed()),
+ t: self.start.elapsed().as_secs_f64(),
active,
waiting,
inactive,
@@ -305,7 +305,7 @@
let pct_idle = current.idle_since(prev);
*prev = current;
self.last_cpu_recording = now;
- let dur = d_as_f64(now.duration_since(self.start));
+ let dur = now.duration_since(self.start).as_secs_f64();
self.cpu_usage.push((dur, 100.0 - pct_idle));
}
@@ -334,7 +334,7 @@
bcx: &BuildContext<'_, '_>,
error: &Option,
) -> CargoResult<()> {
- let duration = d_as_f64(self.start.elapsed());
+ let duration = self.start.elapsed().as_secs_f64();
let timestamp = self.start_str.replace(&['-', ':'][..], "");
let filename = format!("cargo-timing-{}.html", timestamp);
let mut f = BufWriter::new(paths::create(&filename)?);
@@ -616,11 +616,6 @@
}
}
-// Replace with as_secs_f64 when 1.38 hits stable.
-fn d_as_f64(d: Duration) -> f64 {
- (d.as_secs() as f64) + f64::from(d.subsec_nanos()) / 1_000_000_000.0
-}
-
fn render_rustc_info(bcx: &BuildContext<'_, '_>) -> String {
let version = bcx
.rustc()
diff -Nru cargo-0.47.0/src/cargo/core/compiler/unit_dependencies.rs cargo-0.51.0/src/cargo/core/compiler/unit_dependencies.rs
--- cargo-0.47.0/src/cargo/core/compiler/unit_dependencies.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/unit_dependencies.rs 2021-02-04 15:18:32.000000000 +0000
@@ -22,7 +22,7 @@
use crate::core::profiles::{Profile, Profiles, UnitFor};
use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
use crate::core::resolver::Resolve;
-use crate::core::{Package, PackageId, PackageSet, Target, Workspace};
+use crate::core::{Dependency, Package, PackageId, PackageSet, Target, Workspace};
use crate::ops::resolve_all_features;
use crate::util::interning::InternedString;
use crate::util::Config;
@@ -47,6 +47,11 @@
target_data: &'a RustcTargetData,
profiles: &'a Profiles,
interner: &'a UnitInterner,
+
+ /// A set of edges in `unit_dependencies` where (a, b) means that the
+ /// dependency from a to b was added purely because it was a dev-dependency.
+ /// This is used during `connect_run_custom_build_deps`.
+ dev_dependency_edges: HashSet<(Unit, Unit)>,
}
pub fn build_unit_dependencies<'a, 'cfg>(
@@ -62,6 +67,12 @@
profiles: &'a Profiles,
interner: &'a UnitInterner,
) -> CargoResult {
+ if roots.is_empty() {
+ // If -Zbuild-std, don't attach units if there is nothing to build.
+ // Otherwise, other parts of the code may be confused by seeing units
+ // in the dep graph without a root.
+ return Ok(HashMap::new());
+ }
let (std_resolve, std_features) = match std_resolve {
Some((r, f)) => (Some(r), Some(f)),
None => (None, None),
@@ -80,6 +91,7 @@
target_data,
profiles,
interner,
+ dev_dependency_edges: HashSet::new(),
};
let std_unit_deps = calc_deps_of_std(&mut state, std_roots)?;
@@ -92,7 +104,7 @@
attach_std_deps(&mut state, std_roots, std_unit_deps);
}
- connect_run_custom_build_deps(&mut state.unit_dependencies);
+ connect_run_custom_build_deps(&mut state);
// Dependencies are used in tons of places throughout the backend, many of
// which affect the determinism of the build itself. As a result be sure
@@ -161,7 +173,13 @@
// without, once for `--test`). In particular, the lib included for
// Doc tests and examples are `Build` mode here.
let unit_for = if unit.mode.is_any_test() || state.global_mode.is_rustc_test() {
- UnitFor::new_test(state.config)
+ if unit.target.proc_macro() {
+ // Special-case for proc-macros, which are forced to for-host
+ // since they need to link with the proc_macro crate.
+ UnitFor::new_host_test(state.config)
+ } else {
+ UnitFor::new_test(state.config)
+ }
} else if unit.target.is_custom_build() {
// This normally doesn't happen, except `clean` aggressively
// generates all units.
@@ -217,53 +235,37 @@
}
let id = unit.pkg.package_id();
- let filtered_deps = state.resolve().deps(id).filter(|&(_id, deps)| {
- assert!(!deps.is_empty());
- deps.iter().any(|dep| {
- // If this target is a build command, then we only want build
- // dependencies, otherwise we want everything *other than* build
- // dependencies.
- if unit.target.is_custom_build() != dep.is_build() {
- return false;
- }
-
- // If this dependency is **not** a transitive dependency, then it
- // only applies to test/example targets.
- if !dep.is_transitive()
- && !unit.target.is_test()
- && !unit.target.is_example()
- && !unit.mode.is_any_test()
- {
- return false;
- }
-
- // If this dependency is only available for certain platforms,
- // make sure we're only enabling it for that platform.
- if !state.target_data.dep_platform_activated(dep, unit.kind) {
- return false;
- }
-
- // If this is an optional dependency, and the new feature resolver
- // did not enable it, don't include it.
- if dep.is_optional() {
- let features_for = unit_for.map_to_features_for();
+ let filtered_deps = state
+ .deps(unit, unit_for)
+ .into_iter()
+ .filter(|&(_id, deps)| {
+ deps.iter().any(|dep| {
+ // If this target is a build command, then we only want build
+ // dependencies, otherwise we want everything *other than* build
+ // dependencies.
+ if unit.target.is_custom_build() != dep.is_build() {
+ return false;
+ }
- let feats = state.activated_features(id, features_for);
- if !feats.contains(&dep.name_in_toml()) {
+ // If this dependency is **not** a transitive dependency, then it
+ // only applies to test/example targets.
+ if !dep.is_transitive()
+ && !unit.target.is_test()
+ && !unit.target.is_example()
+ && !unit.mode.is_any_test()
+ {
return false;
}
- }
- // If we've gotten past all that, then this dependency is
- // actually used!
- true
- })
- });
- // Separate line to avoid rustfmt indentation. Must collect due to `state` capture.
- let filtered_deps: Vec<_> = filtered_deps.collect();
+ // If we've gotten past all that, then this dependency is
+ // actually used!
+ true
+ })
+ });
let mut ret = Vec::new();
- for (id, _) in filtered_deps {
+ let mut dev_deps = Vec::new();
+ for (id, deps) in filtered_deps {
let pkg = state.get(id);
let lib = match pkg.targets().iter().find(|t| t.is_lib()) {
Some(t) => t,
@@ -275,6 +277,7 @@
// If it is a custom build script, then it *only* has build dependencies.
.with_host_features(unit.target.is_custom_build() || lib.proc_macro());
+ let start = ret.len();
if state.config.cli_unstable().dual_proc_macros && lib.proc_macro() && !unit.kind.is_host()
{
let unit_dep = new_unit_dep(state, unit, pkg, lib, dep_unit_for, unit.kind, mode)?;
@@ -294,7 +297,18 @@
)?;
ret.push(unit_dep);
}
+
+ // If the unit added was a dev-dependency unit, then record that in the
+ // dev-dependencies array. We'll add this to
+ // `state.dev_dependency_edges` at the end and process it later in
+ // `connect_run_custom_build_deps`.
+ if deps.iter().all(|d| !d.is_transitive()) {
+ for dep in ret[start..].iter() {
+ dev_deps.push((unit.clone(), dep.unit.clone()));
+ }
+ }
}
+ state.dev_dependency_edges.extend(dev_deps);
// If this target is a build script, then what we've collected so far is
// all we need. If this isn't a build script, then it depends on the
@@ -404,16 +418,10 @@
/// Returns the dependencies necessary to document a package.
fn compute_deps_doc(unit: &Unit, state: &mut State<'_, '_>) -> CargoResult> {
- let target_data = state.target_data;
let deps = state
- .resolve()
- .deps(unit.pkg.package_id())
- .filter(|&(_id, deps)| {
- deps.iter().any(|dep| match dep.kind() {
- DepKind::Normal => target_data.dep_platform_activated(dep, unit.kind),
- _ => false,
- })
- });
+ .deps(unit, UnitFor::new_normal())
+ .into_iter()
+ .filter(|&(_id, deps)| deps.iter().any(|dep| dep.kind() == DepKind::Normal));
// To document a library, we depend on dependencies actually being
// built. If we're documenting *all* libraries, then we also depend on
@@ -612,7 +620,7 @@
let features = state.activated_features(pkg.package_id(), features_for);
let unit = state
.interner
- .intern(pkg, target, profile, kind, mode, features, state.is_std);
+ .intern(pkg, target, profile, kind, mode, features, state.is_std, 0);
Ok(UnitDep {
unit,
unit_for,
@@ -632,17 +640,18 @@
///
/// Here we take the entire `deps` map and add more dependencies from execution
/// of one build script to execution of another build script.
-fn connect_run_custom_build_deps(unit_dependencies: &mut UnitGraph) {
+fn connect_run_custom_build_deps(state: &mut State<'_, '_>) {
let mut new_deps = Vec::new();
{
+ let state = &*state;
// First up build a reverse dependency map. This is a mapping of all
// `RunCustomBuild` known steps to the unit which depends on them. For
// example a library might depend on a build script, so this map will
// have the build script as the key and the library would be in the
// value's set.
let mut reverse_deps_map = HashMap::new();
- for (unit, deps) in unit_dependencies.iter() {
+ for (unit, deps) in state.unit_dependencies.iter() {
for dep in deps {
if dep.unit.mode == CompileMode::RunCustomBuild {
reverse_deps_map
@@ -662,11 +671,13 @@
// `links`, then we depend on that package's build script! Here we use
// `dep_build_script` to manufacture an appropriate build script unit to
// depend on.
- for unit in unit_dependencies
+ for unit in state
+ .unit_dependencies
.keys()
.filter(|k| k.mode == CompileMode::RunCustomBuild)
{
- // This is the lib that runs this custom build.
+ // This list of dependencies all depend on `unit`, an execution of
+ // the build script.
let reverse_deps = match reverse_deps_map.get(unit) {
Some(set) => set,
None => continue,
@@ -674,17 +685,35 @@
let to_add = reverse_deps
.iter()
- // Get all deps for lib.
- .flat_map(|reverse_dep| unit_dependencies[reverse_dep].iter())
+ // Get all sibling dependencies of `unit`
+ .flat_map(|reverse_dep| {
+ state.unit_dependencies[reverse_dep]
+ .iter()
+ .map(move |a| (reverse_dep, a))
+ })
// Only deps with `links`.
- .filter(|other| {
+ .filter(|(_parent, other)| {
other.unit.pkg != unit.pkg
&& other.unit.target.is_linkable()
&& other.unit.pkg.manifest().links().is_some()
})
+ // Skip dependencies induced via dev-dependencies since
+ // connections between `links` and build scripts only happens
+ // via normal dependencies. Otherwise since dev-dependencies can
+ // be cyclic we could have cyclic build-script executions.
+ .filter_map(move |(parent, other)| {
+ if state
+ .dev_dependency_edges
+ .contains(&((*parent).clone(), other.unit.clone()))
+ {
+ None
+ } else {
+ Some(other)
+ }
+ })
// Get the RunCustomBuild for other lib.
.filter_map(|other| {
- unit_dependencies[&other.unit]
+ state.unit_dependencies[&other.unit]
.iter()
.find(|other_dep| other_dep.unit.mode == CompileMode::RunCustomBuild)
.cloned()
@@ -700,7 +729,11 @@
// And finally, add in all the missing dependencies!
for (unit, new_deps) in new_deps {
- unit_dependencies.get_mut(&unit).unwrap().extend(new_deps);
+ state
+ .unit_dependencies
+ .get_mut(&unit)
+ .unwrap()
+ .extend(new_deps);
}
}
@@ -730,9 +763,49 @@
features.activated_features(pkg_id, features_for)
}
+ fn is_dep_activated(
+ &self,
+ pkg_id: PackageId,
+ features_for: FeaturesFor,
+ dep_name: InternedString,
+ ) -> bool {
+ self.features()
+ .is_dep_activated(pkg_id, features_for, dep_name)
+ }
+
fn get(&self, id: PackageId) -> &'a Package {
self.package_set
.get_one(id)
.unwrap_or_else(|_| panic!("expected {} to be downloaded", id))
}
+
+ /// Returns a filtered set of dependencies for the given unit.
+ fn deps(&self, unit: &Unit, unit_for: UnitFor) -> Vec<(PackageId, &HashSet)> {
+ let pkg_id = unit.pkg.package_id();
+ let kind = unit.kind;
+ self.resolve()
+ .deps(pkg_id)
+ .filter(|&(_id, deps)| {
+ assert!(!deps.is_empty());
+ deps.iter().any(|dep| {
+ // If this dependency is only available for certain platforms,
+ // make sure we're only enabling it for that platform.
+ if !self.target_data.dep_platform_activated(dep, kind) {
+ return false;
+ }
+
+ // If this is an optional dependency, and the new feature resolver
+ // did not enable it, don't include it.
+ if dep.is_optional() {
+ let features_for = unit_for.map_to_features_for();
+ if !self.is_dep_activated(pkg_id, features_for, dep.name_in_toml()) {
+ return false;
+ }
+ }
+
+ true
+ })
+ })
+ .collect()
+ }
}
diff -Nru cargo-0.47.0/src/cargo/core/compiler/unit_graph.rs cargo-0.51.0/src/cargo/core/compiler/unit_graph.rs
--- cargo-0.47.0/src/cargo/core/compiler/unit_graph.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/unit_graph.rs 2021-02-04 15:18:32.000000000 +0000
@@ -16,7 +16,7 @@
/// The dependency unit.
pub unit: Unit,
/// The purpose of this dependency (a dependency for a test, or a build
- /// script, etc.).
+ /// script, etc.). Do not use this after the unit graph has been built.
pub unit_for: UnitFor,
/// The name the parent uses to refer to this dependency.
pub extern_crate_name: InternedString,
diff -Nru cargo-0.47.0/src/cargo/core/compiler/unit.rs cargo-0.51.0/src/cargo/core/compiler/unit.rs
--- cargo-0.47.0/src/cargo/core/compiler/unit.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/compiler/unit.rs 2021-02-04 15:18:32.000000000 +0000
@@ -57,6 +57,18 @@
pub features: Vec,
/// Whether this is a standard library unit.
pub is_std: bool,
+ /// A hash of all dependencies of this unit.
+ ///
+ /// This is used to keep the `Unit` unique in the situation where two
+ /// otherwise identical units need to link to different dependencies. This
+ /// can happen, for example, when there are shared dependencies that need
+ /// to be built with different features between normal and build
+ /// dependencies. See `rebuild_unit_graph_shared` for more on why this is
+ /// done.
+ ///
+ /// This value initially starts as 0, and then is filled in via a
+ /// second-pass after all the unit dependencies have been computed.
+ pub dep_hash: u64,
}
impl UnitInner {
@@ -123,6 +135,8 @@
.field("kind", &self.kind)
.field("mode", &self.mode)
.field("features", &self.features)
+ .field("is_std", &self.is_std)
+ .field("dep_hash", &self.dep_hash)
.finish()
}
}
@@ -164,6 +178,7 @@
mode: CompileMode,
features: Vec,
is_std: bool,
+ dep_hash: u64,
) -> Unit {
let target = match (is_std, target.kind()) {
// This is a horrible hack to support build-std. `libstd` declares
@@ -194,6 +209,7 @@
mode,
features,
is_std,
+ dep_hash,
});
Unit { inner }
}
diff -Nru cargo-0.47.0/src/cargo/core/dependency.rs cargo-0.51.0/src/cargo/core/dependency.rs
--- cargo-0.47.0/src/cargo/core/dependency.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/dependency.rs 2021-02-04 15:18:32.000000000 +0000
@@ -386,8 +386,16 @@
self.source_id(),
id
);
- self.set_version_req(VersionReq::exact(id.version()))
- .set_source_id(id.source_id())
+ let me = Rc::make_mut(&mut self.inner);
+ me.req = VersionReq::exact(id.version());
+
+ // Only update the `precise` of this source to preserve other
+ // information about dependency's source which may not otherwise be
+ // tested during equality/hashing.
+ me.source_id = me
+ .source_id
+ .with_precise(id.source_id().precise().map(|s| s.to_string()));
+ self
}
/// Returns `true` if this is a "locked" dependency, basically whether it has
@@ -405,10 +413,7 @@
}
pub fn is_build(&self) -> bool {
- match self.inner.kind {
- DepKind::Build => true,
- _ => false,
- }
+ matches!(self.inner.kind, DepKind::Build)
}
pub fn is_optional(&self) -> bool {
diff -Nru cargo-0.47.0/src/cargo/core/features.rs cargo-0.51.0/src/cargo/core/features.rs
--- cargo-0.47.0/src/cargo/core/features.rs 2020-07-17 20:39:39.000000000 +0000
+++ cargo-0.51.0/src/cargo/core/features.rs 2021-02-04 15:18:32.000000000 +0000
@@ -25,7 +25,7 @@
//! use core::{Feature, Features};
//!
//! let feature = Feature::launch_into_space();
-//! package.manifest().features().require(feature).chain_err(|| {
+//! package.manifest().unstable_features().require(feature).chain_err(|| {
//! "launching Cargo into space right now is unstable and may result in \
//! unintended damage to your codebase, use with caution"
//! })?;
@@ -197,9 +197,6 @@
// Overriding profiles for dependencies.
[stable] profile_overrides: bool,
- // Separating the namespaces for features and dependencies
- [unstable] namespaced_features: bool,
-
// "default-run" manifest option,
[stable] default_run: bool,
@@ -333,7 +330,8 @@
/// and then test for your flag or your value and act accordingly.
///
/// If you have any trouble with this, please let us know!
-#[derive(Default, Debug)]
+#[derive(Default, Debug, Deserialize)]
+#[serde(default, rename_all = "kebab-case")]
pub struct CliUnstable {
pub print_im_a_teapot: bool,
pub unstable_options: bool,
@@ -347,16 +345,36 @@
pub mtime_on_use: bool,
pub named_profiles: bool,
pub binary_dep_depinfo: bool,
+ #[serde(deserialize_with = "deserialize_build_std")]
pub build_std: Option>,
+ pub build_std_features: Option>,
pub timings: Option>,
pub doctest_xcompile: bool,
pub panic_abort_tests: bool,
pub jobserver_per_rustc: bool,
pub features: Option>,
- pub crate_versions: bool,
pub separate_nightlies: bool,
pub multitarget: bool,
pub rustdoc_map: bool,
+ pub terminal_width: Option