diff options
Diffstat (limited to 'src/lib/git_events.rs')
| -rw-r--r-- | src/lib/git_events.rs | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index e907a9b..b39e797 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -40,6 +40,30 @@ pub fn get_commit_id_from_patch(event: &Event) -> Result<String> { | |||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | pub fn get_parent_commit_from_patch( | ||
| 44 | event: &Event, | ||
| 45 | git_repo: Option<&Repo>, | ||
| 46 | ) -> Result<String> { | ||
| 47 | if let Ok(parent) = tag_value(event, "parent-commit") { | ||
| 48 | return Ok(parent); | ||
| 49 | } | ||
| 50 | |||
| 51 | let metadata = crate::mbox_parser::parse_mbox_patch(&event.content) | ||
| 52 | .context("failed to parse patch for timestamp")?; | ||
| 53 | let timestamp = metadata.committer_timestamp.unwrap_or(metadata.author_timestamp); | ||
| 54 | |||
| 55 | if let Some(repo) = git_repo { | ||
| 56 | if let Some(best_guess) = repo | ||
| 57 | .find_best_guess_parent_commit(timestamp) | ||
| 58 | .context("failed to find best guess parent commit")? | ||
| 59 | { | ||
| 60 | return Ok(best_guess.to_string()); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | bail!("no parent-commit tag and could not determine best guess parent") | ||
| 65 | } | ||
| 66 | |||
| 43 | pub fn get_event_root(event: &nostr::Event) -> Result<EventId> { | 67 | pub fn get_event_root(event: &nostr::Event) -> Result<EventId> { |
| 44 | Ok(EventId::parse( | 68 | Ok(EventId::parse( |
| 45 | event | 69 | event |
| @@ -88,11 +112,27 @@ pub fn event_is_revision_root(event: &Event) -> bool { | |||
| 88 | } | 112 | } |
| 89 | 113 | ||
| 90 | pub fn patch_supports_commit_ids(event: &Event) -> bool { | 114 | pub fn patch_supports_commit_ids(event: &Event) -> bool { |
| 91 | event.kind.eq(&Kind::GitPatch) | 115 | if !event.kind.eq(&Kind::GitPatch) { |
| 92 | && event | 116 | return false; |
| 93 | .tags | 117 | } |
| 94 | .iter() | 118 | |
| 95 | .any(|t| !t.as_slice().is_empty() && t.as_slice()[0].eq("commit-pgp-sig")) | 119 | if event |
| 120 | .tags | ||
| 121 | .iter() | ||
| 122 | .any(|t| !t.as_slice().is_empty() && t.as_slice()[0].eq("commit-pgp-sig")) | ||
| 123 | { | ||
| 124 | return true; | ||
| 125 | } | ||
| 126 | |||
| 127 | if event | ||
| 128 | .tags | ||
| 129 | .iter() | ||
| 130 | .any(|t| !t.as_slice().is_empty() && t.as_slice()[0].eq("parent-commit")) | ||
| 131 | { | ||
| 132 | return true; | ||
| 133 | } | ||
| 134 | |||
| 135 | crate::mbox_parser::parse_mbox_patch(&event.content).is_ok() | ||
| 96 | } | 136 | } |
| 97 | 137 | ||
| 98 | pub fn event_is_valid_pr_or_pr_update(event: &Event) -> bool { | 138 | pub fn event_is_valid_pr_or_pr_update(event: &Event) -> bool { |