git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adam Roben <aroben@apple.com>
To: Eric Wong <normalperson@yhbt.net>
Cc: git@vger.kernel.org, Adam Roben <aroben@apple.com>
Subject: [PATCH] git-svn: Added 'find-rev' command
Date: Fri, 27 Apr 2007 11:57:53 -0700	[thread overview]
Message-ID: <117770027350-git-send-email-aroben@apple.com> (raw)

This patch adds a new 'find-rev' command to git-svn that lets you easily
translate between SVN revision numbers and git tree-ish.

Signed-off-by: Adam Roben <aroben@apple.com>
---
 Documentation/git-svn.txt |    5 +++++
 git-svn.perl              |   24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index a0d34e0..a35b9de 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -159,6 +159,11 @@ New features:
 Any other arguments are passed directly to `git log'
 
 --
+'find-rev'::
+	When given an SVN revision number of the form 'rN', returns the
+	corresponding git commit hash.  When given a tree-ish, returns the
+	corresponding SVN revision number.
+
 'set-tree'::
 	You should consider using 'dcommit' instead of this command.
 	Commit specified commit or tree objects to SVN.  This relies on
diff --git a/git-svn.perl b/git-svn.perl
index 7b5f8ab..4be8576 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -141,6 +141,8 @@ my %cmd = (
 			  'color' => \$Git::SVN::Log::color,
 			  'pager=s' => \$Git::SVN::Log::pager,
 			} ],
+	'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish",
+			{ } ],
 	'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory",
 			{ 'merge|m|M' => \$_merge,
 			  'verbose|v' => \$_verbose,
@@ -428,6 +430,28 @@ sub cmd_dcommit {
 	command_noisy(@finish, $gs->refname);
 }
 
+sub cmd_find_rev {
+	my $revision_or_hash = shift;
+	my $result;
+	if ($revision_or_hash =~ /^r\d+$/) {
+		my $desired_revision = substr($revision_or_hash, 1);
+		my ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');
+		while (my $hash = <$fh>) {
+			chomp($hash);
+			my (undef, $rev, undef) = cmt_metadata($hash);
+			if ($rev && $rev eq $desired_revision) {
+				$result = $hash;
+				last;
+			}
+		}
+		command_close_pipe($fh, $ctx);
+	} else {
+		my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
+		$result = $rev;
+	}
+	print "$result\n" if $result;
+}
+
 sub cmd_rebase {
 	command_noisy(qw/update-index --refresh/);
 	my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
-- 
1.5.2.rc0.75.g959b-dirty

             reply	other threads:[~2007-04-27 19:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-27 18:57 Adam Roben [this message]
2007-04-27 19:30 ` [PATCH] git-svn: Added 'find-rev' command Eric Wong
2007-04-28  6:13   ` Junio C Hamano
2007-04-28 10:50     ` Eric Wong
2007-04-28 19:22       ` Adam Roben

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=117770027350-git-send-email-aroben@apple.com \
    --to=aroben@apple.com \
    --cc=git@vger.kernel.org \
    --cc=normalperson@yhbt.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).