Skip to content
Snippets Groups Projects
Commit c2c53e127be1 authored by Georges Racinet's avatar Georges Racinet
Browse files

rhgitaly::gitlab::state::has_gitlab_default_branch

This new method does a bit less than `get_gitlab_default_branch` and can
be used as fast async (yet somewhat fuzzy) way to know if the repository is
empty.
parent ebcf11181944
No related branches found
No related tags found
2 merge requests!245Update MSRV to 1.73 and merge stable,!244RHGitaly ListRefs implementation
......@@ -35,7 +35,7 @@
use bytes::{Bytes, BytesMut};
use std::io;
use std::path::Path;
use tokio::fs::{read, File};
use tokio::fs::{metadata, read, File};
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, BufReader};
use tokio_stream::wrappers::LinesStream;
use tokio_stream::StreamExt;
......@@ -93,6 +93,9 @@
}
}
// Yes `..` is ugly, but in truth that file should be in the `store/` subdirectory
const DEFAULT_BRANCH_RPATH: &str = "../default_gitlab_branch";
/// Read the GitLab default branch information
///
/// This notion is stateful and repository specific (can be tweaked by users). It is independent
......@@ -100,8 +103,7 @@
pub async fn get_gitlab_default_branch(
store_vfs: &Path,
) -> Result<Option<Vec<u8>>, StateFileError> {
// Yes `..` is ugly, but in truth that file should be in the `store/` subdirectory
let path = store_vfs.join("../default_gitlab_branch");
let path = store_vfs.join(DEFAULT_BRANCH_RPATH);
Ok(io_error_not_found_as_none(read(&path).await)?)
}
......@@ -105,6 +107,20 @@
Ok(io_error_not_found_as_none(read(&path).await)?)
}
pub async fn has_gitlab_default_branch(store_vfs: &Path) -> Result<bool, StateFileError> {
let path = store_vfs.join(DEFAULT_BRANCH_RPATH);
Ok(match metadata(&path).await {
Ok(md) => Ok(md.len() != 0),
Err(e) => {
if e.kind() == io::ErrorKind::NotFound {
Ok(false)
} else {
Err(e)
}
}
}?)
}
/// A [`Decoder`] for the typed refs file format, allowing to stream [`TypedRef`]s.
///
/// This can be used with [`FramedRead`] to turn any [`AsyncRead`]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment