💾 Archived View for lists.flounder.online › patches › threads › 20210315175744.6493-4-johann@qwertqw… captured on 2022-04-28 at 19:25:24. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

[PATCH mygit 4/5] handle shallow clones

[PATCH mygit 4/5] handle shallow clones

From: johann@qwertqwefsday.eu

Date: Mon, 15 Mar 2021 18:57:43 +0100

Message-Id: 20210315175744.6493-4-johann@qwertqwefsday.eu

To: <~aw/patches@lists.sr.ht>

In-Reply-To: 20210315175744.6493-1-johann@qwertqwefsday.eu

Cc: "Johann150" <johann@qwertqwefsday.eu>

Reply

Export

--------------------------------------

From: Johann150 <johann@qwertqwefsday.eu>

Although unusual for a git server, encountering a shallow clone should

be handled correctly.

---

src/main.rs | 29 ++++++++++++++++++++---------

1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/main.rs b/src/main.rs

index f727880..342248f 100644

--- a/src/main.rs

+++ b/src/main.rs

@@ -111,7 +111,7 @@ async fn repo_home(req: Request<()>) -> tide::Result {

let repo = repo_from_request(&req.param("repo_name")?)?;

if repo.is_empty().unwrap() {

// we would not be able to find HEAD

- return Ok(RepoEmptyTemplate { repo }.into())

+ return Ok(RepoEmptyTemplate { repo }.into());

}

let readme_text = {

@@ -172,15 +172,26 @@ async fn repo_log(req: Request<()>) -> tide::Result {

return Ok(tide::Redirect::temporary(url.to_string()).into());

}

- let mut revwalk = repo.revwalk()?;

- match req.param("ref") {

- Ok(r) => revwalk.push_ref(&format!("refs/heads/{}", r))?,

- _ => revwalk.push_head()?,

+ let commits = if repo.is_shallow() {

+ tide::log::warn!("repository {:?} is only a shallow clone", repo.path());

+ vec![repo.head()?.peel_to_commit().unwrap()]

+ } else {

+ let mut revwalk = repo.revwalk()?;

+ match req.param("ref") {

+ Ok(r) => revwalk.push_ref(&format!("refs/heads/{}", r))?,

+ _ => revwalk.push_head()?,

+ };

+

+ // show newest commits first

+ revwalk

+ .set_sorting(git2::Sort::TIME | git2::Sort::REVERSE)

+ .unwrap();

+

+ revwalk

+ .filter_map(|oid| repo.find_commit(oid.unwrap()).ok().clone()) // TODO error handling

+ .take(100) // Only get first 100 commits

+ .collect()

};

- let commits = revwalk

- .filter_map(|oid| repo.find_commit(oid.unwrap()).ok().clone()) // TODO error handling

- .take(100) // Only get first 100 commits

- .collect();

let tmpl = RepoLogTemplate {

repo: &repo,

commits,

--

2.20.1