nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: oli-obk/cargo_metadata
Pull request #31 (2018-03-11 07:08:08)

Add target_directory to Metadata


Patch:
diff --git a/src/lib.rs b/src/lib.rs
index 788b233..35ddfea 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -106,6 +106,8 @@ pub struct Metadata {
     pub resolve: Option<Resolve>,
     /// Workspace root
     pub workspace_root: String,
+    /// Build directory
+    pub target_directory: String,
     version: usize,
     #[doc(hidden)]
     #[serde(skip)]


Test patch:
diff --git a/tests/selftest.rs b/tests/selftest.rs
index c30b865..d722d7c 100644
--- a/tests/selftest.rs
+++ b/tests/selftest.rs
@@ -2,6 +2,7 @@ extern crate cargo_metadata;
 extern crate semver;
 extern crate serde_json;
 
+use std::env::current_dir;
 use std::path::Path;
 
 use semver::Version;
@@ -12,6 +13,11 @@ use cargo_metadata::{Error, ErrorKind};
 fn metadata() {
     let metadata = cargo_metadata::metadata(None).unwrap();
 
+    assert_eq!(
+        current_dir().unwrap().join("target"),
+        Path::new(&metadata.target_directory)
+    );
+
     assert_eq!(metadata.packages[0].name, "cargo_metadata");
     assert_eq!(metadata.packages[0].targets.len(), 2);
Repository: oli-obk/cargo_metadata
Pull request #87 (2019-09-08 19:38:48)

package.readme should be Option<PathBuf> rather than Option<String>
Since the `Package::readme` field is public this would be a breaking change.
However, the ~aaec6f1~ 5448745  by itself should not break anything, while providing handy accessors, even without the updating (~3706bb2~ 66c3296) `Package::readme` field.


Patch:
diff --git a/src/lib.rs b/src/lib.rs
index f1deb84..91d0a31 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -317,7 +317,7 @@ pub struct Package {
     #[serde(default)]
     pub keywords: Vec<String>,
     /// Readme as given in the `Cargo.toml`
-    pub readme: Option<String>,
+    pub readme: Option<PathBuf>,
     /// Repository as given in the `Cargo.toml`
     pub repository: Option<String>,
     /// Default Rust edition for the package
@@ -360,6 +360,22 @@ pub struct Package {
     __do_not_match_exhaustively: (),
 }
 
+impl Package {
+    /// Full path to the license file if one is present in the manifest
+    pub fn license_file(&self) -> Option<PathBuf> {
+        self.license_file
+            .as_ref()
+            .map(|file| self.manifest_path.join(file))
+    }
+
+    /// Full path to the readme file if one is present in the manifest
+    pub fn readme(&self) -> Option<PathBuf> {
+        self.readme
+            .as_ref()
+            .map(|file| self.manifest_path.join(file))
+    }
+}
+
 /// The source of a package such as crates.io.
 #[derive(Clone, Serialize, Deserialize, Debug)]
 #[serde(transparent)]


Test patch:
diff --git a/tests/test_samples.rs b/tests/test_samples.rs
index fbdaf98..232332f 100644
--- a/tests/test_samples.rs
+++ b/tests/test_samples.rs
@@ -281,7 +281,7 @@ fn all_the_fields() {
     assert!(all.manifest_path.ends_with("all/Cargo.toml"));
     assert_eq!(all.categories, vec!["command-line-utilities"]);
     assert_eq!(all.keywords, vec!["cli"]);
-    assert_eq!(all.readme, Some("README.md".to_string()));
+    assert_eq!(all.readme, Some(PathBuf::from("README.md")));
     assert_eq!(
         all.repository,
         Some("https://github.com/oli-obk/cargo_metadata/".to_string())
Repository: oli-obk/cargo_metadata
Pull request #160 (2021-04-22 15:01:15)

impl Display for DependencyKind
This reuses the Serialize impl for consistency.

Fixes https://github.com/oli-obk/cargo_metadata/issues/156


Patch:
diff --git a/src/dependency.rs b/src/dependency.rs
index 24cb028..5367cdc 100644
--- a/src/dependency.rs
+++ b/src/dependency.rs
@@ -1,5 +1,7 @@
 //! This module contains `Dependency` and the types/functions it uses for deserialization.
 
+use std::fmt;
+
 use camino::Utf8PathBuf;
 use semver::VersionReq;
 use serde::{Deserialize, Deserializer, Serialize};
@@ -29,6 +31,14 @@ impl Default for DependencyKind {
     }
 }
 
+impl fmt::Display for DependencyKind {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        let s = serde_json::to_string(self).unwrap();
+        // skip opening and closing quotes
+        f.write_str(&s[1..s.len() - 1])
+    }
+}
+
 /// The `kind` can be `null`, which is interpreted as the default - `Normal`.
 pub(super) fn parse_dependency_kind<'de, D>(d: D) -> Result<DependencyKind, D::Error>
 where


Test patch:
diff --git a/tests/test_samples.rs b/tests/test_samples.rs
index a0fd55f..533c6ea 100644
--- a/tests/test_samples.rs
+++ b/tests/test_samples.rs
@@ -597,3 +597,11 @@ fn advanced_feature_configuration() {
     });
     assert_eq!(sorted!(all_flag_variants), sorted!(all_features));
 }
+
+#[test]
+fn depkind_to_string() {
+    assert_eq!(DependencyKind::Normal.to_string(), "normal");
+    assert_eq!(DependencyKind::Development.to_string(), "dev");
+    assert_eq!(DependencyKind::Build.to_string(), "build");
+    assert_eq!(DependencyKind::Unknown.to_string(), "Unknown");
+}
Repository: oli-obk/cargo_metadata
Pull request #163 (2021-05-27 11:32:26)

Bump semver to 1.0.0


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index 50b04b0..f22c13b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,8 +12,7 @@ edition = "2018"
 camino = { version = "1.0.1", features = ["serde1"] }
 cargo-platform = "0.1"
 derive_builder = { version = "0.9.0", optional = true }
-semver = { version = "0.11.0", features = ["serde"] }
-semver-parser = "0.10.2"
+semver = { version = "1", features = ["serde"] }
 serde = { version = "1.0.107", features = ["derive"] }
 serde_json = { version = "1.0.59", features = ["unbounded_depth"] }
 


Test patch:
diff --git a/tests/test_samples.rs b/tests/test_samples.rs
index 533c6ea..76d4983 100644
--- a/tests/test_samples.rs
+++ b/tests/test_samples.rs
@@ -138,8 +138,8 @@ fn cargo_version() -> semver::Version {
     assert!(split.len() >= 2, "cargo -V output is unexpected: {}", out);
     let mut ver = semver::Version::parse(split[1]).expect("cargo -V semver could not be parsed");
     // Don't care about metadata, it is awkward to compare.
-    ver.pre = Vec::new();
-    ver.build = Vec::new();
+    ver.pre = semver::Prerelease::EMPTY;
+    ver.build = semver::BuildMetadata::EMPTY;
     ver
 }
Repository: oli-obk/cargo_metadata
Pull request #177 (2022-04-24 09:57:22)

add Metadata::workspace_packages method
Inspired by [this](https://github.com/killercup/cargo-edit/blob/8a14de08c204e77374187f2d9348bae497803909/src/metadata.rs#L26) cargo-edit method, I thought it might be nice to have this functionality in this crate, directly.


Patch:
diff --git a/src/lib.rs b/src/lib.rs
index 3ebcc76..0c57e71 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -158,6 +158,14 @@ impl Metadata {
         let root = self.resolve.as_ref()?.root.as_ref()?;
         self.packages.iter().find(|pkg| &pkg.id == root)
     }
+
+    /// Get the workspace packages.
+    pub fn workspace_packages(&self) -> Vec<&Package> {
+        self.packages
+            .iter()
+            .filter(|&p| self.workspace_members.contains(&p.id))
+            .collect()
+    }
 }
 
 impl<'a> std::ops::Index<&'a PackageId> for Metadata {


Test patch:
diff --git a/tests/selftest.rs b/tests/selftest.rs
index 70b131b..d6ab618 100644
--- a/tests/selftest.rs
+++ b/tests/selftest.rs
@@ -132,6 +132,10 @@ fn metadata_deps() {
 
     assert_eq!(this.name, "cargo_metadata");
 
+    let workspace_packages = metadata.workspace_packages();
+    assert_eq!(workspace_packages.len(), 1);
+    assert_eq!(&workspace_packages[0].id, this_id);
+
     let lib = this
         .targets
         .iter()
Repository: oli-obk/cargo_metadata
Pull request #277 (2024-12-03 11:56:03)

Make `Dependency`'s `source` member the same type as `Package`'s `source` member: `Option<Source>`
They have the exact same representation (i.e. bare string) in the JSON output of `cargo metadata`, so might as well use the same type in `Metadata`.

oli-obk: This will need a breaking change release 🤔 
regexident: > This will need a breaking change release 🤔

It will. It's of no urgency though, so feel free to postpone merging at your discretion.
I just stumbled upon the inconsistency and figured you might appreciate a PR, nothing that's actively in the way.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 308e1bf..de91cef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
 - Updated dependencies:
   - `thiserror` from `1.0.31` to `2.0.3`
   - `derive_builder` from `0.12` to `0.20`
+- Made `Dependency`'s `source` member the same type as `Package`'s `source` member: `Option<Source>`.
 
 ### Removed
 
diff --git a/src/dependency.rs b/src/dependency.rs
index 293b9d9..09b8850 100644
--- a/src/dependency.rs
+++ b/src/dependency.rs
@@ -8,6 +8,8 @@ use derive_builder::Builder;
 use semver::VersionReq;
 use serde::{Deserialize, Deserializer, Serialize};
 
+use crate::Source;
+
 #[derive(Eq, PartialEq, Clone, Debug, Copy, Hash, Serialize, Deserialize, Default)]
 /// Dependencies can come in three kinds
 pub enum DependencyKind {
@@ -51,7 +53,7 @@ pub struct Dependency {
     /// Name as given in the `Cargo.toml`
     pub name: String,
     /// The source of dependency
-    pub source: Option<String>,
+    pub source: Option<Source>,
     /// The required version
     pub req: VersionReq,
     /// The kind of dependency this is


Test patch:
diff --git a/tests/test_samples.rs b/tests/test_samples.rs
index 3596693..24ee5bb 100644
--- a/tests/test_samples.rs
+++ b/tests/test_samples.rs
@@ -6,6 +6,7 @@ extern crate serde_json;
 use camino::Utf8PathBuf;
 use cargo_metadata::{
     ArtifactDebuginfo, CargoOpt, DependencyKind, Edition, Message, Metadata, MetadataCommand,
+    Source,
 };
 
 /// Output from oldest version ever supported (1.24).
@@ -239,7 +240,9 @@ fn all_the_fields() {
         .unwrap();
     assert_eq!(
         bitflags.source,
-        Some("registry+https://github.com/rust-lang/crates.io-index".to_string())
+        Some(Source {
+            repr: "registry+https://github.com/rust-lang/crates.io-index".to_string()
+        })
     );
     assert!(bitflags.optional);
     assert_eq!(bitflags.req, semver::VersionReq::parse("^1.0").unwrap());
Repository: adnanh/webhook
Pull request #371 (2019-12-23 04:07:46)

Make hook package internal
The hook package API is not meant for public consumption.


Patch:
diff --git a/webhook.go b/webhook.go
index c1fab60..69f8a8a 100644
--- a/webhook.go
+++ b/webhook.go
@@ -15,7 +15,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/adnanh/webhook/hook"
+	"github.com/adnanh/webhook/internal/hook"
 	"github.com/codegangsta/negroni"
 	"github.com/gofrs/uuid"
 	"github.com/gorilla/mux"


Test patch:
diff --git a/hook/hook.go b/internal/hook/hook.go
similarity index 100%
rename from hook/hook.go
rename to internal/hook/hook.go
diff --git a/hook/hook_test.go b/internal/hook/hook_test.go
similarity index 99%
rename from hook/hook_test.go
rename to internal/hook/hook_test.go
index ce6d760..dfb4874 100644
--- a/hook/hook_test.go
+++ b/internal/hook/hook_test.go
@@ -373,10 +373,10 @@ var hooksLoadFromFileTests = []struct {
 	asTemplate bool
 	ok         bool
 }{
-	{"../hooks.json.example", false, true},
-	{"../hooks.yaml.example", false, true},
-	{"../hooks.json.tmpl.example", true, true},
-	{"../hooks.yaml.tmpl.example", true, true},
+	{"../../hooks.json.example", false, true},
+	{"../../hooks.yaml.example", false, true},
+	{"../../hooks.json.tmpl.example", true, true},
+	{"../../hooks.yaml.tmpl.example", true, true},
 	{"", false, true},
 	// failures
 	{"missing.json", false, false},
diff --git a/webhook_test.go b/webhook_test.go
index 6f46527..dc678cc 100644
--- a/webhook_test.go
+++ b/webhook_test.go
@@ -18,7 +18,7 @@ import (
 	"text/template"
 	"time"
 
-	"github.com/adnanh/webhook/hook"
+	"github.com/adnanh/webhook/internal/hook"
 )
 
 func TestStaticParams(t *testing.T) {