| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | use std::{path::PathBuf, pin::Pin}; |
| 7 | |
| 8 | use tokio::io::AsyncRead; |
| 9 | |
| 10 | use crate::domain::{ |
| 11 | BranchRow, CommitDetail, CommitSummary, DomainError, GitRef, GrepHit, ImportSource, ObjectId, |
| 12 | OrgName, PasswordHash, RefName, RepoName, RepoPath, TagRow, TagSummary, TreeEntry, |
| 13 | }; |
| 14 | |
| 15 | use super::blame::Blame; |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | pub trait PasswordHasher: Send + Sync { |
| 23 | |
| 24 | fn hash(&self, plaintext: &str) -> Result<PasswordHash, PasswordError>; |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | fn verify(&self, plaintext: &str, hash: &PasswordHash) -> Result<bool, PasswordError>; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 36 | pub struct PasswordError(String); |
| 37 | |
| 38 | impl PasswordError { |
| 39 | pub fn new(message: impl Into<String>) -> Self { |
| 40 | Self(message.into()) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl std::fmt::Display for PasswordError { |
| 45 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 46 | write!(f, "password hashing failed: {}", self.0) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | impl std::error::Error for PasswordError {} |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | pub trait GitStorage: Send + Sync { |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | fn init_bare( |
| 72 | &self, |
| 73 | handle: &OrgName, |
| 74 | name: &RepoName, |
| 75 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | fn remove( |
| 83 | &self, |
| 84 | handle: &OrgName, |
| 85 | name: &RepoName, |
| 86 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | fn rename( |
| 99 | &self, |
| 100 | handle: &OrgName, |
| 101 | from: &RepoName, |
| 102 | to: &RepoName, |
| 103 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | fn set_default_branch( |
| 120 | &self, |
| 121 | handle: &OrgName, |
| 122 | name: &RepoName, |
| 123 | branch: &RefName, |
| 124 | ) -> impl Future<Output = Result<(), GitStorageError>> + Send; |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | fn repo_path(&self, handle: &OrgName, name: &RepoName) -> PathBuf; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | #[derive(Debug)] |
| 135 | pub enum GitStorageError { |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | AlreadyExists, |
| 142 | |
| 143 | Backend(Box<dyn std::error::Error + Send + Sync>), |
| 144 | } |
| 145 | |
| 146 | impl GitStorageError { |
| 147 | pub fn backend(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 148 | Self::Backend(error.into()) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | impl std::fmt::Display for GitStorageError { |
| 153 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 154 | match self { |
| 155 | Self::AlreadyExists => f.write_str("a repository already exists at that path"), |
| 156 | Self::Backend(error) => write!(f, "git storage failure: {error}"), |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | impl std::error::Error for GitStorageError { |
| 162 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 163 | match self { |
| 164 | Self::AlreadyExists => None, |
| 165 | Self::Backend(error) => Some(&**error), |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | pub type ByteStream = Pin<Box<dyn AsyncRead + Send>>; |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 183 | pub enum GitMethod { |
| 184 | Get, |
| 185 | Post, |
| 186 | } |
| 187 | |
| 188 | impl GitMethod { |
| 189 | pub fn as_str(self) -> &'static str { |
| 190 | match self { |
| 191 | Self::Get => "GET", |
| 192 | Self::Post => "POST", |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | pub struct GitRequest { |
| 206 | pub method: GitMethod, |
| 207 | |
| 208 | pub path_info: String, |
| 209 | |
| 210 | pub query: String, |
| 211 | pub content_type: Option<String>, |
| 212 | |
| 213 | |
| 214 | |
| 215 | pub content_encoding: Option<String>, |
| 216 | pub content_length: Option<String>, |
| 217 | |
| 218 | |
| 219 | pub git_protocol: Option<String>, |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | pub allow_receive_pack: bool, |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | pub remote_user: Option<String>, |
| 237 | pub body: ByteStream, |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | pub struct GitResponse { |
| 246 | pub status: u16, |
| 247 | pub headers: Vec<(String, String)>, |
| 248 | pub body: ByteStream, |
| 249 | } |
| 250 | |
| 251 | |
| 252 | |
| 253 | impl std::fmt::Debug for GitRequest { |
| 254 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 255 | f.debug_struct("GitRequest") |
| 256 | .field("method", &self.method) |
| 257 | .field("path_info", &self.path_info) |
| 258 | .field("query", &self.query) |
| 259 | .field("content_type", &self.content_type) |
| 260 | .field("content_encoding", &self.content_encoding) |
| 261 | .field("content_length", &self.content_length) |
| 262 | .field("git_protocol", &self.git_protocol) |
| 263 | .field("allow_receive_pack", &self.allow_receive_pack) |
| 264 | .field("remote_user", &self.remote_user) |
| 265 | .finish_non_exhaustive() |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | impl std::fmt::Debug for GitResponse { |
| 270 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 271 | f.debug_struct("GitResponse") |
| 272 | .field("status", &self.status) |
| 273 | .field("headers", &self.headers) |
| 274 | .finish_non_exhaustive() |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | pub trait GitProtocolServer: Send + Sync { |
| 283 | fn serve( |
| 284 | &self, |
| 285 | request: GitRequest, |
| 286 | ) -> impl Future<Output = Result<GitResponse, GitProtocolError>> + Send; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | #[derive(Debug)] |
| 295 | pub struct GitProtocolError(Box<dyn std::error::Error + Send + Sync>); |
| 296 | |
| 297 | impl GitProtocolError { |
| 298 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 299 | Self(error.into()) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | impl std::fmt::Display for GitProtocolError { |
| 304 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 305 | write!(f, "git protocol failure: {}", self.0) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | impl std::error::Error for GitProtocolError { |
| 310 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 311 | Some(&*self.0) |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 322 | pub struct WebhookRequest { |
| 323 | pub url: String, |
| 324 | pub headers: Vec<(String, String)>, |
| 325 | pub body: Vec<u8>, |
| 326 | } |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 334 | pub struct WebhookOutcome { |
| 335 | |
| 336 | |
| 337 | pub status: Option<u16>, |
| 338 | |
| 339 | |
| 340 | pub body: String, |
| 341 | pub duration: std::time::Duration, |
| 342 | } |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | pub trait WebhookSender: Send + Sync { |
| 350 | fn send(&self, request: WebhookRequest) -> impl Future<Output = WebhookOutcome> + Send; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 359 | pub struct Blob { |
| 360 | pub id: ObjectId, |
| 361 | pub size: u64, |
| 362 | pub content: Option<Vec<u8>>, |
| 363 | } |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | pub trait GitQuery: Send + Sync { |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | fn default_branch( |
| 386 | &self, |
| 387 | handle: &OrgName, |
| 388 | name: &RepoName, |
| 389 | ) -> impl Future<Output = Result<Option<RefName>, GitQueryError>> + Send; |
| 390 | |
| 391 | |
| 392 | fn resolve( |
| 393 | &self, |
| 394 | handle: &OrgName, |
| 395 | name: &RepoName, |
| 396 | rev: &RefName, |
| 397 | ) -> impl Future<Output = Result<Option<ObjectId>, GitQueryError>> + Send; |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | fn list_tree( |
| 404 | &self, |
| 405 | handle: &OrgName, |
| 406 | name: &RepoName, |
| 407 | rev: &RefName, |
| 408 | path: &RepoPath, |
| 409 | ) -> impl Future<Output = Result<Option<Vec<TreeEntry>>, GitQueryError>> + Send; |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | fn read_blob( |
| 415 | &self, |
| 416 | handle: &OrgName, |
| 417 | name: &RepoName, |
| 418 | rev: &RefName, |
| 419 | path: &RepoPath, |
| 420 | max_bytes: u64, |
| 421 | ) -> impl Future<Output = Result<Option<Blob>, GitQueryError>> + Send; |
| 422 | |
| 423 | |
| 424 | fn log( |
| 425 | &self, |
| 426 | handle: &OrgName, |
| 427 | name: &RepoName, |
| 428 | rev: &RefName, |
| 429 | limit: usize, |
| 430 | ) -> impl Future<Output = Result<Vec<CommitSummary>, GitQueryError>> + Send; |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | fn list_refs( |
| 447 | &self, |
| 448 | handle: &OrgName, |
| 449 | name: &RepoName, |
| 450 | ) -> impl Future<Output = Result<Vec<GitRef>, GitQueryError>> + Send; |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | fn count_commits( |
| 459 | &self, |
| 460 | handle: &OrgName, |
| 461 | name: &RepoName, |
| 462 | rev: &RefName, |
| 463 | ) -> impl Future<Output = Result<u64, GitQueryError>> + Send; |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | fn latest_tag( |
| 475 | &self, |
| 476 | handle: &OrgName, |
| 477 | name: &RepoName, |
| 478 | ) -> impl Future<Output = Result<Option<TagSummary>, GitQueryError>> + Send; |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | fn commit( |
| 491 | &self, |
| 492 | handle: &OrgName, |
| 493 | name: &RepoName, |
| 494 | rev: &RefName, |
| 495 | ) -> impl Future<Output = Result<Option<CommitDetail>, GitQueryError>> + Send; |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | fn diff( |
| 515 | &self, |
| 516 | handle: &OrgName, |
| 517 | name: &RepoName, |
| 518 | base: Option<&ObjectId>, |
| 519 | head: &ObjectId, |
| 520 | max_bytes: u64, |
| 521 | ) -> impl Future<Output = Result<RawDiff, GitQueryError>> + Send; |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | fn merge_base( |
| 530 | &self, |
| 531 | handle: &OrgName, |
| 532 | name: &RepoName, |
| 533 | base: &ObjectId, |
| 534 | head: &ObjectId, |
| 535 | ) -> impl Future<Output = Result<Option<ObjectId>, GitQueryError>> + Send; |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | fn log_between( |
| 546 | &self, |
| 547 | handle: &OrgName, |
| 548 | name: &RepoName, |
| 549 | base: Option<&ObjectId>, |
| 550 | head: &ObjectId, |
| 551 | limit: usize, |
| 552 | ) -> impl Future<Output = Result<Vec<CommitSummary>, GitQueryError>> + Send; |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | fn branches( |
| 571 | &self, |
| 572 | handle: &OrgName, |
| 573 | name: &RepoName, |
| 574 | ) -> impl Future<Output = Result<Vec<BranchRow>, GitQueryError>> + Send; |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | fn tags( |
| 582 | &self, |
| 583 | handle: &OrgName, |
| 584 | name: &RepoName, |
| 585 | ) -> impl Future<Output = Result<Vec<TagRow>, GitQueryError>> + Send; |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | fn grep( |
| 600 | &self, |
| 601 | handle: &OrgName, |
| 602 | name: &RepoName, |
| 603 | commit: &ObjectId, |
| 604 | query: &str, |
| 605 | limit: usize, |
| 606 | ) -> impl Future<Output = Result<Vec<GrepHit>, GitQueryError>> + Send; |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | fn blame( |
| 623 | &self, |
| 624 | handle: &OrgName, |
| 625 | name: &RepoName, |
| 626 | rev: &RefName, |
| 627 | path: &RepoPath, |
| 628 | ) -> impl Future<Output = Result<Option<Blame>, GitQueryError>> + Send; |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | fn ref_snapshot( |
| 650 | &self, |
| 651 | handle: &OrgName, |
| 652 | name: &RepoName, |
| 653 | ) -> impl Future<Output = Result<Vec<(RefName, ObjectId)>, GitQueryError>> + Send; |
| 654 | } |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 666 | pub struct RawDiff { |
| 667 | |
| 668 | |
| 669 | pub numstat: Vec<u8>, |
| 670 | |
| 671 | |
| 672 | pub patch: Vec<u8>, |
| 673 | |
| 674 | pub truncated: bool, |
| 675 | } |
| 676 | |
| 677 | #[derive(Debug)] |
| 678 | pub struct GitQueryError { |
| 679 | kind: GitQueryErrorKind, |
| 680 | source: Box<dyn std::error::Error + Send + Sync>, |
| 681 | } |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 689 | pub enum GitQueryErrorKind { |
| 690 | Failed, |
| 691 | TimedOut, |
| 692 | } |
| 693 | |
| 694 | impl GitQueryError { |
| 695 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 696 | Self { |
| 697 | kind: GitQueryErrorKind::Failed, |
| 698 | source: error.into(), |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | |
| 703 | pub fn timed_out(limit: std::time::Duration) -> Self { |
| 704 | Self { |
| 705 | kind: GitQueryErrorKind::TimedOut, |
| 706 | source: format!("git did not finish within {limit:?}").into(), |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | pub fn kind(&self) -> GitQueryErrorKind { |
| 711 | self.kind |
| 712 | } |
| 713 | |
| 714 | pub fn is_timeout(&self) -> bool { |
| 715 | self.kind == GitQueryErrorKind::TimedOut |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | impl std::fmt::Display for GitQueryError { |
| 720 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 721 | match self.kind { |
| 722 | GitQueryErrorKind::Failed => { |
| 723 | write!(f, "could not read the repository: {}", self.source) |
| 724 | } |
| 725 | GitQueryErrorKind::TimedOut => { |
| 726 | write!(f, "reading the repository took too long: {}", self.source) |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | impl std::error::Error for GitQueryError { |
| 733 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 734 | Some(&*self.source) |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 744 | pub enum ArchiveFormat { |
| 745 | TarGz, |
| 746 | Zip, |
| 747 | } |
| 748 | |
| 749 | impl ArchiveFormat { |
| 750 | |
| 751 | |
| 752 | pub fn as_str(self) -> &'static str { |
| 753 | match self { |
| 754 | Self::TarGz => "tar.gz", |
| 755 | Self::Zip => "zip", |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | pub fn content_type(self) -> &'static str { |
| 765 | match self { |
| 766 | Self::TarGz => "application/gzip", |
| 767 | Self::Zip => "application/zip", |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | |
| 773 | |
| 774 | impl std::str::FromStr for ArchiveFormat { |
| 775 | type Err = DomainError; |
| 776 | |
| 777 | fn from_str(value: &str) -> std::result::Result<Self, Self::Err> { |
| 778 | match value { |
| 779 | "tar.gz" => Ok(Self::TarGz), |
| 780 | "zip" => Ok(Self::Zip), |
| 781 | other => Err(DomainError::validation( |
| 782 | "format", |
| 783 | format!("unknown archive format {other:?}"), |
| 784 | )), |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 796 | pub struct ArchiveRequest { |
| 797 | pub handle: OrgName, |
| 798 | pub name: RepoName, |
| 799 | pub format: ArchiveFormat, |
| 800 | pub commit: ObjectId, |
| 801 | |
| 802 | |
| 803 | pub prefix: String, |
| 804 | } |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | pub trait GitArchive: Send + Sync { |
| 813 | fn archive( |
| 814 | &self, |
| 815 | request: ArchiveRequest, |
| 816 | ) -> impl Future<Output = Result<ByteStream, GitArchiveError>> + Send; |
| 817 | } |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | #[derive(Debug)] |
| 824 | pub struct GitArchiveError(Box<dyn std::error::Error + Send + Sync>); |
| 825 | |
| 826 | impl GitArchiveError { |
| 827 | pub fn new(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self { |
| 828 | Self(error.into()) |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | impl std::fmt::Display for GitArchiveError { |
| 833 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 834 | write!(f, "could not archive the repository: {}", self.0) |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | impl std::error::Error for GitArchiveError { |
| 839 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 840 | Some(&*self.0) |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | pub trait GitImport: Send + Sync { |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | fn mirror( |
| 863 | &self, |
| 864 | handle: &OrgName, |
| 865 | name: &RepoName, |
| 866 | source: &ImportSource, |
| 867 | ) -> impl Future<Output = Result<(), GitImportError>> + Send; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | #[derive(Debug)] |
| 877 | pub struct GitImportError(String); |
| 878 | |
| 879 | impl GitImportError { |
| 880 | pub fn new(message: impl Into<String>) -> Self { |
| 881 | Self(message.into()) |
| 882 | } |
| 883 | |
| 884 | |
| 885 | |
| 886 | pub fn message(&self) -> &str { |
| 887 | &self.0 |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | impl std::fmt::Display for GitImportError { |
| 892 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 893 | write!(f, "could not import the repository: {}", self.0) |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | impl std::error::Error for GitImportError {} |