{"thread":{"id":"7877","subject":"[PATCH] git-svn: Added 'find-rev' command","startedAt":"2007-04-27T18:57:53Z","lastAt":"2007-04-28T19:22:13Z","messageCount":5,"participants":["Adam Roben","Eric Wong","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"40620","messageId":"117770027350-git-send-email-aroben@apple.com","threadId":"7877","inReplyTo":null,"subject":"[PATCH] git-svn: Added 'find-rev' command","fromName":"Adam Roben","fromEmail":"aroben@apple.com","sentAt":"2007-04-27T18:57:53Z","receivedAt":"2007-04-27T18:57:53Z","isPatch":true,"sender":{"key":"aroben@apple.com","avatar":"https://gravatar.com/avatar/9d3697e1de53890adf241331f4b970bdd2b18962b2ff0b8028ebb00e085807f8?d=mp&s=160"},"body":"This patch adds a new 'find-rev' command to git-svn that lets you easily\ntranslate between SVN revision numbers and git tree-ish.\n\nSigned-off-by: Adam Roben <aroben@apple.com>\n---\n Documentation/git-svn.txt |    5 +++++\n git-svn.perl              |   24 ++++++++++++++++++++++++\n 2 files changed, 29 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex a0d34e0..a35b9de 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -159,6 +159,11 @@ New features:\n Any other arguments are passed directly to `git log'\n \n --\n+'find-rev'::\n+\tWhen given an SVN revision number of the form 'rN', returns the\n+\tcorresponding git commit hash.  When given a tree-ish, returns the\n+\tcorresponding SVN revision number.\n+\n 'set-tree'::\n \tYou should consider using 'dcommit' instead of this command.\n \tCommit specified commit or tree objects to SVN.  This relies on\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 7b5f8ab..4be8576 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -141,6 +141,8 @@ my %cmd = (\n \t\t\t  'color' => \\$Git::SVN::Log::color,\n \t\t\t  'pager=s' => \\$Git::SVN::Log::pager,\n \t\t\t} ],\n+\t'find-rev' => [ \\&cmd_find_rev, \"Translate between SVN revision numbers and tree-ish\",\n+\t\t\t{ } ],\n \t'rebase' => [ \\&cmd_rebase, \"Fetch and rebase your working directory\",\n \t\t\t{ 'merge|m|M' => \\$_merge,\n \t\t\t  'verbose|v' => \\$_verbose,\n@@ -428,6 +430,28 @@ sub cmd_dcommit {\n \tcommand_noisy(@finish, $gs->refname);\n }\n \n+sub cmd_find_rev {\n+\tmy $revision_or_hash = shift;\n+\tmy $result;\n+\tif ($revision_or_hash =~ /^r\\d+$/) {\n+\t\tmy $desired_revision = substr($revision_or_hash, 1);\n+\t\tmy ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');\n+\t\twhile (my $hash = <$fh>) {\n+\t\t\tchomp($hash);\n+\t\t\tmy (undef, $rev, undef) = cmt_metadata($hash);\n+\t\t\tif ($rev && $rev eq $desired_revision) {\n+\t\t\t\t$result = $hash;\n+\t\t\t\tlast;\n+\t\t\t}\n+\t\t}\n+\t\tcommand_close_pipe($fh, $ctx);\n+\t} else {\n+\t\tmy (undef, $rev, undef) = cmt_metadata($revision_or_hash);\n+\t\t$result = $rev;\n+\t}\n+\tprint \"$result\\n\" if $result;\n+}\n+\n sub cmd_rebase {\n \tcommand_noisy(qw/update-index --refresh/);\n \tmy ($url, $rev, $uuid, $gs) = working_head_info('HEAD');\n-- \n1.5.2.rc0.75.g959b-dirty\n"},{"id":"40623","messageId":"20070427193004.GC12375@untitled","threadId":"7877","inReplyTo":"117770027350-git-send-email-aroben@apple.com","subject":"Re: [PATCH] git-svn: Added 'find-rev' command","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-04-27T19:30:04Z","receivedAt":"2007-04-27T19:30:04Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Adam Roben <aroben@apple.com> wrote:\n> This patch adds a new 'find-rev' command to git-svn that lets you easily\n> translate between SVN revision numbers and git tree-ish.\n\nLooks useful.\n\nAcked-by: Eric Wong <normalperson@yhbt.net>\n\n> Signed-off-by: Adam Roben <aroben@apple.com>\n> ---\n>  Documentation/git-svn.txt |    5 +++++\n>  git-svn.perl              |   24 ++++++++++++++++++++++++\n>  2 files changed, 29 insertions(+), 0 deletions(-)\n> \n> diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\n> index a0d34e0..a35b9de 100644\n> --- a/Documentation/git-svn.txt\n> +++ b/Documentation/git-svn.txt\n> @@ -159,6 +159,11 @@ New features:\n>  Any other arguments are passed directly to `git log'\n>  \n>  --\n> +'find-rev'::\n> +\tWhen given an SVN revision number of the form 'rN', returns the\n> +\tcorresponding git commit hash.  When given a tree-ish, returns the\n> +\tcorresponding SVN revision number.\n> +\n>  'set-tree'::\n>  \tYou should consider using 'dcommit' instead of this command.\n>  \tCommit specified commit or tree objects to SVN.  This relies on\n> diff --git a/git-svn.perl b/git-svn.perl\n> index 7b5f8ab..4be8576 100755\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -141,6 +141,8 @@ my %cmd = (\n>  \t\t\t  'color' => \\$Git::SVN::Log::color,\n>  \t\t\t  'pager=s' => \\$Git::SVN::Log::pager,\n>  \t\t\t} ],\n> +\t'find-rev' => [ \\&cmd_find_rev, \"Translate between SVN revision numbers and tree-ish\",\n> +\t\t\t{ } ],\n>  \t'rebase' => [ \\&cmd_rebase, \"Fetch and rebase your working directory\",\n>  \t\t\t{ 'merge|m|M' => \\$_merge,\n>  \t\t\t  'verbose|v' => \\$_verbose,\n> @@ -428,6 +430,28 @@ sub cmd_dcommit {\n>  \tcommand_noisy(@finish, $gs->refname);\n>  }\n>  \n> +sub cmd_find_rev {\n> +\tmy $revision_or_hash = shift;\n> +\tmy $result;\n> +\tif ($revision_or_hash =~ /^r\\d+$/) {\n> +\t\tmy $desired_revision = substr($revision_or_hash, 1);\n> +\t\tmy ($fh, $ctx) = command_output_pipe('rev-list', 'HEAD');\n> +\t\twhile (my $hash = <$fh>) {\n> +\t\t\tchomp($hash);\n> +\t\t\tmy (undef, $rev, undef) = cmt_metadata($hash);\n> +\t\t\tif ($rev && $rev eq $desired_revision) {\n> +\t\t\t\t$result = $hash;\n> +\t\t\t\tlast;\n> +\t\t\t}\n> +\t\t}\n> +\t\tcommand_close_pipe($fh, $ctx);\n> +\t} else {\n> +\t\tmy (undef, $rev, undef) = cmt_metadata($revision_or_hash);\n> +\t\t$result = $rev;\n> +\t}\n> +\tprint \"$result\\n\" if $result;\n> +}\n> +\n>  sub cmd_rebase {\n>  \tcommand_noisy(qw/update-index --refresh/);\n>  \tmy ($url, $rev, $uuid, $gs) = working_head_info('HEAD');\n> -- \n> 1.5.2.rc0.75.g959b-dirty\n> \n\n-- \nEric Wong\n"},{"id":"40646","messageId":"7vbqh9kov9.fsf@assigned-by-dhcp.cox.net","threadId":"7877","inReplyTo":"20070427193004.GC12375@untitled","subject":"Re: [PATCH] git-svn: Added 'find-rev' command","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-28T06:13:46Z","receivedAt":"2007-04-28T06:13:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <normalperson@yhbt.net> writes:\n\n> Adam Roben <aroben@apple.com> wrote:\n>> This patch adds a new 'find-rev' command to git-svn that lets you easily\n>> translate between SVN revision numbers and git tree-ish.\n>\n> Looks useful.\n>\n> Acked-by: Eric Wong <normalperson@yhbt.net>\n\nBut looks quite wasteful.  Why not run \"rev-list -v\" or\nsomething instead of running cat-file on revision one-by-one?\n"},{"id":"40651","messageId":"20070428105016.GA11271@muzzle","threadId":"7877","inReplyTo":"7vbqh9kov9.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-svn: Added 'find-rev' command","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-04-28T10:50:16Z","receivedAt":"2007-04-28T10:50:16Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Eric Wong <normalperson@yhbt.net> writes:\n> \n> > Adam Roben <aroben@apple.com> wrote:\n> >> This patch adds a new 'find-rev' command to git-svn that lets you easily\n> >> translate between SVN revision numbers and git tree-ish.\n> >\n> > Looks useful.\n> >\n> > Acked-by: Eric Wong <normalperson@yhbt.net>\n> \n> But looks quite wasteful.  Why not run \"rev-list -v\" or\n> something instead of running cat-file on revision one-by-one?\n\nDidn't know about \"rev-list -v\", but I just checked and it still has the\nlimited-size buffer that --pretty=raw has.\n\n\"git-svn log\" only runs cat-file if it can't find a git-svn-id: line at\nthe bottom.  (I used log --abbrev-commit --pretty=raw).\n\nSorry about the premature Ack, I hadn't had my coffee yet at that point\n(and now I'm half awake :x)\n\nAdam:\n\nHowever, since we're not fetching ranges...\n\nYou can do $gs->rev_db_get($rev_nr) to easily find a commit given a\nrevision.  Bonus points if this works independently of the current HEAD\nso you can look up revision numbers on different branches.  (git-svn log\nshould be made to support this, too)\n\n\n-- \nEric Wong\n"},{"id":"40671","messageId":"CB101F10-559A-4FB9-A76B-E185943BAF2A@apple.com","threadId":"7877","inReplyTo":"20070428105016.GA11271@muzzle","subject":"Re: [PATCH] git-svn: Added 'find-rev' command","fromName":"Adam Roben","fromEmail":"aroben@apple.com","sentAt":"2007-04-28T19:22:13Z","receivedAt":"2007-04-28T19:22:13Z","isPatch":true,"sender":{"key":"aroben@apple.com","avatar":"https://gravatar.com/avatar/9d3697e1de53890adf241331f4b970bdd2b18962b2ff0b8028ebb00e085807f8?d=mp&s=160"},"body":"On Apr 28, 2007, at 3:50 AM, Eric Wong wrote:\n\n> Adam:\n>\n> However, since we're not fetching ranges...\n>\n> You can do $gs->rev_db_get($rev_nr) to easily find a commit given a\n> revision.  Bonus points if this works independently of the current  \n> HEAD\n> so you can look up revision numbers on different branches.  (git- \n> svn log\n> should be made to support this, too)\n\n    OK, I'll do that and send out a new patch.\n\n-Adam\n"}]}