{"thread":{"id":"7895","subject":"[PATCH] git-svn: Add 'find-rev' command","startedAt":"2007-04-29T08:35:27Z","lastAt":"2007-04-29T22:25:44Z","messageCount":4,"participants":["Adam Roben","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"40700","messageId":"1177835727239-git-send-email-aroben@apple.com","threadId":"7895","inReplyTo":null,"subject":"[PATCH] git-svn: Add 'find-rev' command","fromName":"Adam Roben","fromEmail":"aroben@apple.com","sentAt":"2007-04-29T08:35:27Z","receivedAt":"2007-04-29T08:35:27Z","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---\nThis is an updated version of my previous patch that takes Eric and Junio's\ncomments into account.\n\n Documentation/git-svn.txt |    6 ++++++\n git-svn.perl              |   23 +++++++++++++++++++++++\n 2 files changed, 29 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex a0d34e0..482c862 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -159,6 +159,12 @@ 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+        corresponding git commit hash (this can optionally be followed by a\n+        tree-ish to specify which branch should be searched).  When given a\n+        tree-ish, returns the corresponding 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..30e4a41 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,27 @@ 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 $head = shift;\n+\t\t$head ||= 'HEAD';\n+\t\tmy @refs;\n+\t\tmy (undef, undef, undef, $gs) = working_head_info($head, \\@refs);\n+\t\tunless ($gs) {\n+\t\t\tdie \"Unable to determine upstream SVN information from \",\n+\t\t\t    \"$head history\\n\";\n+\t\t}\n+\t\tmy $desired_revision = substr($revision_or_hash, 1);\n+\t\t$result = $gs->rev_db_get($desired_revision);\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":"40708","messageId":"20070429183515.GF12375@untitled","threadId":"7895","inReplyTo":"1177835727239-git-send-email-aroben@apple.com","subject":"Re: [PATCH] git-svn: Add 'find-rev' command","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-04-29T18:35:15Z","receivedAt":"2007-04-29T18:35:15Z","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\nAcked-by: Eric Wong <normalperson@yhbt.net>\n\nAlso, if you have time, can you get this (and 'log') to understand\nrevision numbers even if they're not from the working HEAD?  Thanks.\n\n> Signed-off-by: Adam Roben <aroben@apple.com>\n> ---\n> This is an updated version of my previous patch that takes Eric and Junio's\n> comments into account.\n> \n>  Documentation/git-svn.txt |    6 ++++++\n>  git-svn.perl              |   23 +++++++++++++++++++++++\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..482c862 100644\n> --- a/Documentation/git-svn.txt\n> +++ b/Documentation/git-svn.txt\n> @@ -159,6 +159,12 @@ 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> +        corresponding git commit hash (this can optionally be followed by a\n> +        tree-ish to specify which branch should be searched).  When given a\n> +        tree-ish, returns the corresponding 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..30e4a41 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,27 @@ 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 $head = shift;\n> +\t\t$head ||= 'HEAD';\n> +\t\tmy @refs;\n> +\t\tmy (undef, undef, undef, $gs) = working_head_info($head, \\@refs);\n> +\t\tunless ($gs) {\n> +\t\t\tdie \"Unable to determine upstream SVN information from \",\n> +\t\t\t    \"$head history\\n\";\n> +\t\t}\n> +\t\tmy $desired_revision = substr($revision_or_hash, 1);\n> +\t\t$result = $gs->rev_db_get($desired_revision);\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-- \nEric Wong\n"},{"id":"40713","messageId":"31790C65-1FE6-4BD4-B8D3-B285F0F0422A@apple.com","threadId":"7895","inReplyTo":"20070429183515.GF12375@untitled","subject":"Re: [PATCH] git-svn: Add 'find-rev' command","fromName":"Adam Roben","fromEmail":"aroben@apple.com","sentAt":"2007-04-29T20:31:34Z","receivedAt":"2007-04-29T20:31:34Z","isPatch":true,"sender":{"key":"aroben@apple.com","avatar":"https://gravatar.com/avatar/9d3697e1de53890adf241331f4b970bdd2b18962b2ff0b8028ebb00e085807f8?d=mp&s=160"},"body":"On Apr 29, 2007, at 11:35 AM, Eric Wong wrote:\n\n> Also, if you have time, can you get this (and 'log') to understand\n> revision numbers even if they're not from the working HEAD?  Thanks.\n\n    Won't the following code accomplish that for find-rev? Perhaps I  \nmisunderstand you.\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 $head = shift;\n>> +\t\t$head ||= 'HEAD';\n>> +\t\tmy @refs;\n>> +\t\tmy (undef, undef, undef, $gs) = working_head_info($head, \\@refs);\n\n-Adam\n"},{"id":"40723","messageId":"20070429222544.GB1800@untitled","threadId":"7895","inReplyTo":"31790C65-1FE6-4BD4-B8D3-B285F0F0422A@apple.com","subject":"Re: [PATCH] git-svn: Add 'find-rev' command","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-04-29T22:25:44Z","receivedAt":"2007-04-29T22:25:44Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Adam Roben <aroben@apple.com> wrote:\n> On Apr 29, 2007, at 11:35 AM, Eric Wong wrote:\n> \n> >Also, if you have time, can you get this (and 'log') to understand\n> >revision numbers even if they're not from the working HEAD?  Thanks.\n> \n>    Won't the following code accomplish that for find-rev? Perhaps I  \n> misunderstand you.\n\nworking_head_info() only calls rev-list for a given head.\n\nYou should probably iterate through (like fetch_all does)\neach remote and do rev_db_get via the Git::SVN object.\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 $head = shift;\n> >>+\t\t$head ||= 'HEAD';\n> >>+\t\tmy @refs;\n> >>+\t\tmy (undef, undef, undef, $gs) = working_head_info($head, \n> >>\\@refs);\n\n-- \nEric Wong\n"}]}