diff mbox series

[3/8] Delete remote branch after tests are done

Message ID 20180720115728.19312-3-ruscur@russell.cc
State Accepted
Headers show
Series [1/8] Convert from hyper to reqwest | expand

Commit Message

Russell Currey July 20, 2018, 11:57 a.m. UTC
This left a bunch of unused remote branches up, which makes everything slower
because there's a bunch of git objects, so fix that.

This led to a little cleanup of the push function.

Signed-off-by: Russell Currey <ruscur@russell.cc>
---
 src/git.rs  | 13 ++++++++++---
 src/main.rs |  5 ++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Andrew Donnellan July 23, 2018, 12:55 a.m. UTC | #1
On 20/07/18 21:57, Russell Currey wrote:
> This left a bunch of unused remote branches up, which makes everything slower
> because there's a bunch of git objects, so fix that.
> 
> This led to a little cleanup of the push function.
> 
> Signed-off-by: Russell Currey <ruscur@russell.cc>

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

Part of me thinks it would be nice to make this configurable, e.g. I'd 
like to keep the branch around on failure to give an easy git ref to 
point people to for further debugging. This would best be done along 
with some way of deleting branches after a week or something like that, 
which might be a bit out of scope for snowpatch.
diff mbox series

Patch

diff --git a/src/git.rs b/src/git.rs
index bc93009..d025d03 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -15,7 +15,7 @@ 
 //
 
 use git2::build::CheckoutBuilder;
-use git2::{Commit, Cred, Error, PushOptions, Remote, Repository};
+use git2::{Branch, Commit, Cred, Error, PushOptions, Remote, Repository};
 
 use std::path::Path;
 use std::process::{Command, Output};
@@ -33,10 +33,17 @@  pub fn get_latest_commit(repo: &Repository) -> Commit {
 
 pub fn push_to_remote(
     remote: &mut Remote,
-    branch: &str,
+    branch: &Branch,
+    delete: bool,
     mut opts: &mut PushOptions,
 ) -> Result<(), Error> {
-    let refspecs: &[&str] = &[&format!("+{}/{}", GIT_REF_BASE, branch)];
+    let action = if delete { ":" } else { "+" };
+    let refspecs: &[&str] = &[&format!(
+        "{}{}/{}",
+        action,
+        GIT_REF_BASE,
+        branch.name().unwrap().unwrap()
+    )];
     remote.push(refspecs, Some(&mut opts))
 }
 
diff --git a/src/main.rs b/src/main.rs
index 5bf6187..027ceae 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -205,7 +205,7 @@  fn test_patch(
         let output = git::apply_patch(&repo, path);
 
         if output.is_ok() {
-            git::push_to_remote(&mut remote, &tag, &mut push_opts).unwrap();
+            git::push_to_remote(&mut remote, &branch, false, &mut push_opts).unwrap();
         }
 
         git::checkout_branch(&repo, &branch_name);
@@ -270,6 +270,9 @@  fn test_patch(
             .unwrap();
         results.append(&mut test.join().unwrap());
 
+        // Delete the remote branch now it's not needed any more
+        git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap();
+
         if !test_all_branches {
             break;
         }