From 22360f8c25f4d02ca2a72fdf2425a780a4c2ebbd Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 15 Jun 2023 15:36:09 +0200 Subject: [PATCH] radicle: Change review data in patch COB * `CodeLocation` had a `blob` and `commit` field. These are redundant, since the review lives under a revision. We also change the line range to be diff-compatible, with an old and new range. The ranges are optional to account for different scenarios like file deletion, move etc. * `CodeComment` had redundant getters which were removed in favor of public fields. We also remove the `timestamp` field, as it will be the same as the review timestamp. --- radicle-httpd/src/api/v1/projects.rs | 9 +--- radicle/src/cob/patch.rs | 62 ++++++---------------------- 2 files changed, 15 insertions(+), 56 deletions(-) diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 9d864f00..9f97d5bb 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -2309,16 +2309,11 @@ mod routes { "inline": [ { "location": { - "blob": "82eb77880c693655bce074e3dbbd9fa711dc018b", "path": "./README.md", - "commit": HEAD, - "lines": { - "start": 1, - "end": 3, - }, + "old": null, + "new": null, }, "comment": "This is a comment on line 1", - "timestamp": TIMESTAMP, } ], "timestamp": TIMESTAMP, diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index e69052f3..adec0021 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -729,18 +729,16 @@ impl fmt::Display for Verdict { } } -/// Code location, used for attaching comments. +/// Code location, used for attaching comments to diffs. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CodeLocation { - /// File being commented on. - pub blob: git::Oid, - /// Path of file being commented on. + /// Path of file. pub path: PathBuf, - /// Commit commented on. - pub commit: git::Oid, - /// Line range commented on. - pub lines: Range, + /// Line range on old file. `None` for added files. + pub old: Option>, + /// Line range on new file. `None` for deleted files. + pub new: Option>, } impl PartialOrd for CodeLocation { @@ -751,50 +749,19 @@ impl PartialOrd for CodeLocation { impl Ord for CodeLocation { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - ( - &self.blob, - &self.path, - &self.commit, - &self.lines.start, - &self.lines.end, - ) - .cmp(&( - &other.blob, - &other.path, - &other.commit, - &other.lines.start, - &other.lines.end, - )) + (&self.path, &self.old.as_ref().map(|o| (o.start, o.end))) + .cmp(&(&other.path, &other.new.as_ref().map(|o| (o.start, o.end)))) } } -/// Comment on code. +/// Comment on code diff. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CodeComment { /// Code location of the comment. - location: CodeLocation, + pub location: CodeLocation, /// Comment. - comment: String, - /// Timestamp. - timestamp: Timestamp, -} - -impl CodeComment { - /// Code location of the comment. - pub fn location(&self) -> &CodeLocation { - &self.location - } - - /// Comment. - pub fn comment(&self) -> &str { - &self.comment - } - - /// Timestamp. - pub fn timestamp(&self) -> &Timestamp { - &self.timestamp - } + pub comment: String, } /// A patch review on a revision. @@ -1835,7 +1802,6 @@ mod test { let ctx = test::setup::Context::new(&tmp); let signer = &ctx.signer; let pr = ctx.branch_with(test::setup::initial_blobs()); - let blob = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d133999").unwrap(); let mut patches = Patches::open(&ctx.project).unwrap(); let mut patch = patches .create( @@ -1854,13 +1820,11 @@ mod test { let inline = vec![CodeComment { location: CodeLocation { - blob, path: Path::new("file.rs").to_path_buf(), - commit: pr.oid, - lines: 1..3, + old: Some(1..3), + new: Some(1..3), }, comment: "Nice!".to_owned(), - timestamp: Timestamp::new(0), }]; patch .review(