git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sam Vilain <sam.vilain@catalyst.net.nz>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: (unknown)
Date: Tue, 20 Mar 2007 11:37:01 +1200	[thread overview]
Message-ID: <20070319234722.CF1FF13A382@magnus.utsl.gen.nz> (raw)
In-Reply-To: <7v4pohka7g.fsf@assigned-by-dhcp.cox.net>

Junio C Hamano wrote:
> If you want to see if A is an ancestor of
> any of B C D..., the standard and most efficient way to do so is
> with rev-list.
>
> 	git rev-list A --not B C D...
>
> will show _nothing_ only when A is an ancestor of one (or more)
> of B C D..., so you invoke it and upon getting the first line of
> output you declare A cannot be removed without reading the
> remainder of the output.

Sure.  I figured the commands I put would only use about 30MB for a
300,000 commit repository, so it wouldn't be too bad.  But I didn't
think of that.

Here we go, also based upon 'next' rather than the result of my
previous patches of the day.

Subject: [PATCH] git-remote: implement prune -c

It would be nice to be able to prune local refs which just point to
some place in the remote; add an option to git-remote prune, with
documentation.

Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
---
 Documentation/git-remote.txt |    5 +++++
 git-remote.perl              |   25 +++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index f96b304..6a28e6c 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -54,6 +54,11 @@ Gives some information about the remote <name>.
 Deletes all stale tracking branches under <name>.
 These stale branches have already been removed from the remote repository
 referenced by <name>, but are still locally available in "remotes/<name>".
++
+With `-c` option, all *local* branches that exist in the history of
+any of the mirrored heads from the remote are removed.  This is useful
+for discarding temporary local branches that you did not make any
+commits to.
 
 
 DISCUSSION
diff --git a/git-remote.perl b/git-remote.perl
index 670bafb..84ac534 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -210,7 +210,7 @@ sub show_mapping {
 }
 
 sub prune_remote {
-	my ($name, $ls_remote) = @_;
+	my ($name, $ls_remote, $clean_local) = @_;
 	if (!exists $remote->{$name}) {
 		print STDERR "No such remote $name\n";
 		return;
@@ -224,6 +224,24 @@ sub prune_remote {
 		my @v = $git->command(qw(rev-parse --verify), "$prefix/$to_prune");
 		$git->command(qw(update-ref -d), "$prefix/$to_prune", $v[0]);
 	}
+	if ( $clean_local ) {
+		my @remote = map { (split " ")[0] }
+			$git->command(qw(for-each-ref), $prefix);
+		my %local = map { (split " ")[2,0] }
+			$git->command(qw(for-each-ref refs/heads));
+		my %not_remote = map { ($_ => undef) }
+			$git->command("rev-list", keys %local, "--not", @remote);
+		# don't delete the current branch
+		my ($checked_out) = $git->command(qw(symbolic-ref HEAD));
+
+		while ( my ($ref, $rev) = each %local ) {
+			next if $checked_out and $ref eq $checked_out;
+			if ( not exists $not_remote{$rev} ) {
+				print "$ref is obsolete\n";
+				$git->command(qw(update-ref -d), $ref, $rev);
+			}
+		}
+	}
 }
 
 sub show_remote {
@@ -310,6 +328,9 @@ elsif ($ARGV[0] eq 'prune') {
 		if ($ARGV[$i] eq '-n') {
 			$ls_remote = 0;
 		}
+		elsif ($ARGV[$i] eq '-c') {
+			$clean_local = 1;
+		}
 		else {
 			last;
 		}
@@ -319,7 +340,7 @@ elsif ($ARGV[0] eq 'prune') {
 		exit(1);
 	}
 	for (; $i < @ARGV; $i++) {
-		prune_remote($ARGV[$i], $ls_remote);
+		prune_remote($ARGV[$i], $ls_remote, $clean_local);
 	}
 }
 elsif ($ARGV[0] eq 'add') {
-- 
1.5.0.2.214.gb318

  reply	other threads:[~2007-03-19 23:47 UTC|newest]

Thread overview: 168+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-18  9:36 [wishlist] git branch -d -r remotename Sam Vilain
2007-03-18 11:01 ` Sam Vilain
2007-03-18 11:01   ` Sam Vilain
2007-03-18 19:42     ` Junio C Hamano
2007-03-18 21:46       ` Sam Vilain
2007-03-19  6:18         ` Junio C Hamano
2007-03-19  6:40           ` Junio C Hamano
2007-03-19 23:37             ` Sam Vilain [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-06-16  3:54 (unknown) 岸洋介
2016-06-12  9:38 (unknown), Financial Service
2016-06-07 14:01 [PATCH v3 0/6] send-email: cleaner tests and quote email Tom Russello
2016-06-08 13:01 ` (unknown), Samuel GROOT
2016-05-16 15:58 (unknown), Nathan Wendt
2016-04-11 19:04 (unknown), miwilliams
2016-04-11 16:02 (unknown) Michael S. Tsirkin
2016-03-28 13:38 (unknown), ratheesh kannoth
2015-12-16  3:02 (unknown), David Greene
2015-12-16  5:57 ` (unknown) Junio C Hamano
2015-12-16  8:44   ` (unknown) Patrick Steinhardt
2015-12-18 17:35     ` (unknown) David Greene
2015-12-14 13:14 (unknown) Ros Sothen
2015-11-06  3:34 (unknown), David Greene
2015-09-28 17:55 (unknown), Kosta Zertsekel
2015-09-19 10:58 (unknown), 戸島達哉
2015-09-01  2:13 (unknown), David Turner
2015-08-05 12:47 (unknown) Ivan Chernyavsky
2015-05-12 12:38 (unknown), Varis Van Rob
2015-05-11 17:56 (unknown), dturner
2015-04-08 20:44 (unknown), Mamta Upadhyay
2015-03-13  1:34 (unknown) cody.taylor
2015-02-25  8:53 (unknown) stefan leijen
2015-02-17 18:14 [PATCH] read-cache.c: free cache entry when refreshing fails Junio C Hamano
2015-02-17 18:27 ` (unknown), Stefan Beller
2015-01-12 20:59 (unknown), امير الاحزان
2014-10-30 12:23 (unknown), Fedor Eftimitsa
2014-09-28 10:51 (unknown) bambecapuno06
2014-09-08 11:36 (unknown), R. Klomp
2014-08-26 11:16 (unknown), mail
2014-07-15 16:31 (unknown), Woody Wu
2014-06-17 17:13 (unknown), David Turner
2014-06-01 21:24 (unknown), C. Benson Manica
2014-05-22 22:35 (unknown), Mrs. Jiang Ming
2014-04-19 14:27 (unknown), Siegel, Suzan
2014-03-19  0:45 (unknown) szager
2014-03-05  8:43 (unknown) Stephanie Bennett
2014-02-20  0:55 (unknown) Bozhidar Bozhev
2013-12-18 14:09 (unknown) Maxime Coste
2013-08-07 12:54 (unknown), a a
2013-05-25  3:57 (unknown), Kirill Berezin
2013-05-20  9:58 [PATCH 0/6] t5000: add test for pax extended header generation René Scharfe
2013-05-20  9:58 ` [PATCH 6/6] t5000: test long filenames René Scharfe
2013-05-20 19:55   ` Eric Sunshine
     [not found]     ` <CAPig+cTitT9Z+2pxeNh3dXi4b7X738qpkUnEmTi2yvQoCPtHqA@mail.g mail.com>
2013-05-20 20:01       ` (unknown), Marty Landman
2013-05-17 18:02 (unknown), ASHISH VERMA
2012-12-28 16:43 (unknown) Eric S. Raymond
2012-12-28 19:33 ` (unknown) Junio C Hamano
2012-10-17 12:16 (unknown), Marco Siegl | buerosiegl.com
2012-06-12 21:12 (unknown), rohit sood
2012-05-06 14:17 (unknown), Bruce Zu
2012-05-06 14:13 (unknown), Bruce Zu
2012-05-06 13:54 (unknown), Bruce Zu
2012-03-13 12:18 (unknown), Adam Kicak
2012-02-15  3:12 (unknown), Chris Leong
2012-02-09 23:58 (unknown), Zbigniew Jędrzejewski-Szmek
2012-02-08  0:41 (unknown), mstormo
2012-02-05 20:41 [PATCH] Change include order in two compat/ files to avoid compiler warning Junio C Hamano
2012-02-05 22:32 ` (unknown), Ben Walton
2012-01-10 23:56 (unknown), Steven Line
2011-11-10 22:56 (unknown), Marcel Schaible
2011-11-02 16:38 (unknown), Ben Walton
2011-08-18  6:36 (unknown) milki
2011-08-04 17:27 (unknown) Hin-Tak Leung
2011-05-26  9:02 (unknown) Nicole Hamilt
2011-02-02 17:31 (unknown), Kamol Siesan
2010-12-28 22:56 (unknown), COCA COLA
2010-12-27  6:07 (unknown), COCA COLA
2010-09-20 16:37 (unknown), Leonid Podolny
2010-09-17 18:39 (unknown), Michael Scholl
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-05-07 21:46 (unknown), Mr Chen Guan
2010-03-25  5:53 (unknown) выгнать 
2010-03-19 21:12 (unknown), Michael Cox
2010-03-08 21:56 (unknown) Timur Aydin
2010-02-25  5:55 (unknown), yingshou guo
2010-01-22  2:14 (unknown), Horst H. von Brand
2009-09-12 13:00 (unknown) Tito
2009-07-24 21:21 [PATCH 0/2] Section renaming can lose content Alex Vandiver
2009-07-24 21:21 ` [PATCH 1/2] Make section_name_match start on '[', and return the length on success Alex Vandiver
2009-07-24 21:21   ` [PATCH 2/2] After renaming a section, print any trailing variable definitions Alex Vandiver
2009-07-24 22:11     ` Nanako Shiraishi
2009-07-24 23:39       ` Junio C Hamano
2009-07-25  0:28         ` (unknown), Nanako Shiraishi
2009-07-16 19:22 (unknown) Henrik Austad
2009-06-23  1:07 (unknown) Larry D'Anna
2009-05-27 13:28 (unknown), David Forman
2009-05-13  5:11 (unknown), Tom H
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-11 18:57 (unknown) Don Slutz
2009-05-10 22:48 [JGIT PATCH 1/2] Fix deadlock in native git protocol client for upload-pack Shawn O. Pearce
2009-05-10 22:48 ` [JGIT PATCH 2/2] Decrease the fetch pack client buffer to the lower minimum Shawn O. Pearce
2009-05-11  0:43   ` Junio C Hamano
2009-05-11  0:55     ` Shawn O. Pearce
2009-05-11  3:51       ` Junio C Hamano
2009-05-11 14:10         ` Shawn O. Pearce
2009-05-11 14:23           ` (unknown), Carl Mercier
2009-05-07 17:01 (unknown), Bevan Watkiss
2009-04-16 23:17 (unknown), Fawad Hassan Ismail
2009-03-30  5:03 (unknown), David Aguilar
2009-03-27 20:39 (unknown), Lachlan Deck
2009-03-16 19:06 undoing something John Dlugosz
2009-03-16 19:14 ` Junio C Hamano
2009-03-16 19:48   ` John Dlugosz
2009-03-16 21:45     ` (unknown), Nanako Shiraishi
2009-03-13  8:21 (unknown) Werner Riener
2009-02-06  9:45 (unknown), info
2009-02-06  9:43 (unknown), info
2009-01-09 19:02 (unknown) nathan.panike
2008-10-05 23:36 (unknown), Robin Rosenberg
2008-08-21 19:15 (unknown) bpeeluk
2008-08-13 14:54 (unknown), aneesh.kumar
2008-06-23 20:54 (unknown), VIP Casino Club
2008-06-16 20:02 (unknown) amery
2008-06-16 19:42 (unknown) amery
2008-05-10 22:32 (unknown), Krzysztof Kowalczyk
2008-01-20 21:59 (unknown), Marc-André Lureau
2007-12-05 19:00 [PATCH 0/6] builtin-remote Johannes Schindelin
2007-12-05 19:00 ` (unknown) Johannes Schindelin
2007-11-26 20:00 (unknown) Michael Dressel
2007-11-11 13:08 (unknown) Michael Dressel
2007-11-01 20:44 (unknown), Francesco Pretto
2007-11-01 14:23 (unknown) Heikki Orsila
2007-10-22 18:16 (unknown) racin
2007-10-13  4:01 (unknown), Michael Witten
2007-09-04 13:59 (unknown) Russ Brown
2007-08-19 22:04 (unknown) Luciano Rocha
2007-07-01 18:25 (unknown) Sean D'Epagnier
2007-06-13  0:50 [PATCH] Interpret :/<pattern> as a regular expression Johannes Schindelin
2007-06-13  4:52 ` Junio C Hamano
2007-06-13 11:17   ` (unknown) Johannes Schindelin
2007-06-03 15:30 (unknown) Randal L. Schwartz
2007-05-06  3:51 (unknown), Aaron Gray
2007-04-04 16:59 (unknown) Geert Bosch
2006-11-21 22:24 (unknown) Johannes Schindelin
2006-10-25 14:50 (unknown) andyparkins
2006-10-25 14:49 (unknown) andyparkins
2006-10-25 18:41 ` (unknown) Junio C Hamano
2006-10-25 14:49 (unknown) andyparkins
2006-10-25 14:47 (unknown) andyparkins
2006-10-25 14:53 ` (unknown) Jakub Narebski
2006-10-25 15:10   ` (unknown) Andy Parkins
2006-10-25 15:31     ` (unknown) Karl Hasselström
2006-10-25 18:38     ` (unknown) Junio C Hamano
2006-10-25 22:03       ` (unknown) Andy Parkins
2006-10-25 22:16         ` (unknown) Junio C Hamano
2006-10-25 22:20           ` (unknown) Junio C Hamano
2006-10-26  7:14             ` (unknown) Andy Parkins
2006-10-26 13:22             ` (unknown) Josef Weidendorfer
2006-10-26 15:35               ` (unknown) Linus Torvalds
2006-10-25 22:16         ` (unknown) Shawn Pearce
2006-10-20 14:24 (unknown) andyparkins
2006-10-20 14:24 (unknown) andyparkins
2006-10-20 14:21 (unknown) andyparkins
2006-10-20 13:25 (unknown) andyparkins
2006-10-05  1:54 (unknown), JOSEPH KULIG
2006-09-24 21:55 (unknown) sonny132390
2006-09-21  4:04 (unknown) Nicolas Pitre
2006-09-09 21:46 (unknown), Rajkumar S
2006-08-18 10:35 (unknown), Wolfgang Denk
2006-07-01 15:33 (unknown), Mark
2006-05-26 15:16 (unknown) Juergen Ruehle
2006-05-21 23:53 (unknown) J. Bruce Fields
2006-05-21 23:53 ` (unknown) J. Bruce Fields
2006-05-21 23:53   ` (unknown) J. Bruce Fields
2006-03-28 19:31 (unknown) CustomerDepartament
2006-01-30 18:50 (unknown) Mark Wooding
2005-10-05  6:10 (unknown), Willem Swart
2005-07-23  9:10 (unknown) Junio Hamano
2005-05-28 14:15 (unknown) Thomas Glanzmann
2005-04-26 19:14 (unknown) Bram Cohen
2005-04-22 22:19 (unknown), atani
2005-04-18 22:45 (unknown), Matt W.
2005-04-16  0:51 (unknown) Scott Wright
2005-04-14 22:47 (unknown) Timo Hirvonen
2005-04-14 22:43 (unknown) Timo Hirvonen
2005-04-14 22:30 (unknown), Timo Hirvonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070319234722.CF1FF13A382@magnus.utsl.gen.nz \
    --to=sam.vilain@catalyst.net.nz \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).