-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
use anyhow::{Context, Result}; | ||
use anyhow::{anyhow, Context, Result}; | ||
use std::{io, path::Path}; | ||
|
||
pub fn init() -> Result<()> { | ||
git_repository::init::repository().with_context(|| "Repository initialization failed") | ||
} | ||
|
||
pub fn verify_pack_or_pack_index(path: impl AsRef<Path>, mut out: impl io::Write) -> Result<()> { | ||
let pack = git_odb::pack::File::at(path).with_context(|| "Could not open pack file")?; | ||
pack.verify_checksum().with_context(|| "Failed")?; | ||
let path = path.as_ref(); | ||
let ext = path.extension() | ||
.and_then(|ext| ext.to_str()) | ||
.ok_or_else(|| anyhow!("Cannot determine file type on path without extension '{}', expecting default extensions 'idx' and 'pack'", path.display()))?; | ||
match ext { | ||
"pack" => { | ||
let pack = git_odb::pack::File::at(path).with_context(|| "Could not open pack file")?; | ||
pack.verify_checksum()?; | ||
} | ||
"idx" => { | ||
let idx = git_odb::pack::index::File::at(path) | ||
.with_context(|| "Could not open pack index file")?; | ||
idx.verify_checksum_of_index()?; | ||
} | ||
ext => { | ||
return Err(anyhow!( | ||
"Unknown extension {:?}, expecting 'idx' or 'pack'", | ||
ext | ||
)) | ||
} | ||
} | ||
writeln!(out, "OK")?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters