upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-29 09:01:41 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-29 09:01:41 +0100
commitc60697b3dcc56a2a62f892f48effce802c35a006 (patch)
tree79023fdd4334616268980db6c4e97356a98f6694 /src
parentbe70a0f518bb19f38ea4f1705989ec6af8b042ac (diff)
refactor(remote): abstract `list`
in preparation for managing state via nostr
Diffstat (limited to 'src')
-rw-r--r--src/git_remote_helper.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs
index 793e714..506fd5e 100644
--- a/src/git_remote_helper.rs
+++ b/src/git_remote_helper.rs
@@ -98,22 +98,10 @@ async fn main() -> Result<()> {
98 push(&git_repo.git_repo, url, &mut temp_remote, &stdin, refspec)?; 98 push(&git_repo.git_repo, url, &mut temp_remote, &stdin, refspec)?;
99 } 99 }
100 ["list"] => { 100 ["list"] => {
101 temp_remote.connect(git2::Direction::Fetch)?; 101 list(&mut temp_remote, false)?;
102 for head in temp_remote.list()? {
103 println!("{} {}", head.oid(), head.name());
104 }
105 temp_remote.disconnect()?;
106 println!();
107 } 102 }
108 ["list", "for-push"] => { 103 ["list", "for-push"] => {
109 temp_remote.connect(git2::Direction::Fetch)?; 104 list(&mut temp_remote, true)?;
110 for head in temp_remote.list()? {
111 if head.name() != "HEAD" {
112 println!("{} {}", head.oid(), head.name());
113 }
114 }
115 temp_remote.disconnect()?;
116 println!();
117 } 105 }
118 [] => { 106 [] => {
119 return Ok(()); 107 return Ok(());
@@ -150,6 +138,18 @@ fn nostr_git_url_to_repo_coordinates(url: &str) -> Result<HashSet<Coordinate>> {
150 Ok(repo_coordinattes) 138 Ok(repo_coordinattes)
151} 139}
152 140
141fn list(temp_remote: &mut Remote, for_push: bool) -> Result<()> {
142 temp_remote.connect(git2::Direction::Fetch)?;
143 for head in temp_remote.list()? {
144 if !for_push || head.name() != "HEAD" {
145 println!("{} {}", head.oid(), head.name());
146 }
147 }
148 temp_remote.disconnect()?;
149 println!();
150 Ok(())
151}
152
153fn fetch(temp_remote: &mut Remote, stdin: &Stdin, refstr: &str) -> Result<()> { 153fn fetch(temp_remote: &mut Remote, stdin: &Stdin, refstr: &str) -> Result<()> {
154 temp_remote.connect(git2::Direction::Fetch)?; 154 temp_remote.connect(git2::Direction::Fetch)?;
155 temp_remote.download(&get_refstrs_from_fetch_batch(stdin, refstr)?, None)?; 155 temp_remote.download(&get_refstrs_from_fetch_batch(stdin, refstr)?, None)?;