{"thread":{"id":"1533","subject":"[PATCH] Add merge detection to git-cvsimport","startedAt":"2005-08-16T10:35:27Z","lastAt":"2005-08-17T17:29:28Z","messageCount":4,"participants":["Martin Langhoff","Sven Verdoolaege","Matthias Urlichs"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7355","messageId":"20050816103527.F420A33010C@ng.eduforge.org","threadId":"1533","inReplyTo":null,"subject":"[PATCH] Add merge detection to git-cvsimport","fromName":"Martin Langhoff","fromEmail":"martin@ng.eduforge.org","sentAt":"2005-08-16T10:35:27Z","receivedAt":"2005-08-16T10:35:27Z","isPatch":true,"sender":{"key":"martin@ng.eduforge.org","avatar":null},"body":"[PATCH] Add merge detection to git-cvsimport\n\nAdded -m and -M flags for git-cvsimport to detect merge commits in cvs.\nWhile this trusts the commit message, in repositories where merge commits\nindicate 'merged from FOOBRANCH' the import works surprisingly well.\n\nEven if some merges from CVS are bogus or incomplete, the resulting\nbranches are in better state to go forward (and merge) than without any\nmerge detection.\n\nSigned-off-by: Martin Langhoff <martin.langhoff@gmail.com>\n---\n\n Documentation/git-cvsimport-script.txt |   13 ++++++++-\n git-cvsimport-script                   |   48 +++++++++++++++++++++++++++++---\n 2 files changed, 56 insertions(+), 5 deletions(-)\n\n066d2cb2435a963ee40e4899a76848ea51e972d2\ndiff --git a/Documentation/git-cvsimport-script.txt b/Documentation/git-cvsimport-script.txt\n--- a/Documentation/git-cvsimport-script.txt\n+++ b/Documentation/git-cvsimport-script.txt\n@@ -11,7 +11,8 @@ SYNOPSIS\n --------\n 'git-cvsimport-script' [ -o <branch-for-HEAD> ] [ -h ] [ -v ]\n \t\t\t[ -d <CVSROOT> ] [ -p <options-for-cvsps> ]\n-\t\t\t[ -C <GIT_repository> ] [ -i ] [ -k ] [ <CVS_module> ]\n+\t\t\t[ -C <GIT_repository> ] [ -i ] [ -k ] \n+\t\t\t[ -m ] [ -M regex ] [ <CVS_module> ]\n \n \n DESCRIPTION\n@@ -57,6 +58,16 @@ OPTIONS\n \n \tIf you need to pass multiple options, separate them with a comma.\n \n+-m::    \n+\tAttempt to detect merges based on the commit message. This option\n+\twill enable default regexes that try to capture the name source \n+\tbranch name from the commit message. \n+\n+-M <regex>::\n+\tAttempt to detect merges based on the commit message with a custom\n+\tregex. It can be used with -m to also see the default regexes. \n+\tYou must escape forward slashes. \n+\n -v::\n \tVerbosity: let 'cvsimport' report what it is doing.\n \ndiff --git a/git-cvsimport-script b/git-cvsimport-script\n--- a/git-cvsimport-script\n+++ b/git-cvsimport-script\n@@ -28,19 +28,19 @@ use POSIX qw(strftime dup2);\n $SIG{'PIPE'}=\"IGNORE\";\n $ENV{'TZ'}=\"UTC\";\n \n-our($opt_h,$opt_o,$opt_v,$opt_k,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i);\n+our($opt_h,$opt_o,$opt_v,$opt_k,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_m,$opt_M);\n \n sub usage() {\n \tprint STDERR <<END;\n Usage: ${\\basename $0}     # fetch/update GIT from CVS\n        [ -o branch-for-HEAD ] [ -h ] [ -v ] [ -d CVSROOT ]\n        [ -p opts-for-cvsps ] [ -C GIT_repository ] [ -z fuzz ]\n-       [ -i ] [ -k ] [ CVS_module ]\n+       [ -i ] [ -k ] [ -m ] [ -M regex] [ CVS_module ]\n END\n \texit(1);\n }\n \n-getopts(\"hivko:d:p:C:z:\") or usage();\n+getopts(\"hivmko:d:p:C:z:M:\") or usage();\n usage if $opt_h;\n \n @ARGV <= 1 or usage();\n@@ -70,11 +70,19 @@ if ($#ARGV == 0) {\n \t    die 'Failed to open CVS/Repository';\n \t$cvs_tree = <$f>;\n \tchomp $cvs_tree;\n-\tclose $f\n+\tclose $f;\n } else {\n \tusage();\n }\n \n+our @mergerx = ();\n+if ($opt_m) {\n+\t@mergerx = ( qr/\\W(?:from|of|merge|merging|merged) (\\w+)/i );\n+}\n+if ($opt_M) {\n+\tpush (@mergerx, qr/$opt_M/);\n+}\n+\n select(STDERR); $|=1; select(STDOUT);\n \n \n@@ -374,6 +382,22 @@ sub getwd() {\n \treturn $pwd;\n }\n \n+\n+sub get_headref($$) {\n+    my $name    = shift;\n+    my $git_dir = shift; \n+    my $sha;\n+    \n+    if (open(C,\"$git_dir/refs/heads/$name\")) {\n+\tchomp($sha = <C>);\n+\tclose(C);\n+\tlength($sha) == 40\n+\t    or die \"Cannot get head id for $name ($sha): $!\\n\";\n+    }\n+    return $sha;\n+}\n+\n+\n -d $git_tree\n \tor mkdir($git_tree,0777)\n \tor die \"Could not create $git_tree: $!\";\n@@ -548,6 +572,22 @@ my $commit = sub {\n \n \t\tmy @par = ();\n \t\t@par = (\"-p\",$parent) if $parent;\n+\n+\t\t# loose detection of merges\n+\t\t# based on the commit msg\n+\t\tforeach my $rx (@mergerx) {\n+\t\t\tif ($logmsg =~ $rx) {\n+\t\t\t\tmy $mparent = $1;\n+\t\t\t\tif ($mparent eq 'HEAD') { $mparent = 'origin'};\n+\t\t\t\tif ( -e \"$git_dir/refs/heads/$mparent\") {\n+\t\t\t\t\t$mparent = get_headref($mparent, $git_dir);\n+\t\t\t\t\tpush @par, '-p', $mparent;\n+\t\t\t\t\t# printing here breaks import # \n+\t\t\t\t\t# # print \"Merge parent branch: $mparent\\n\" if $opt_v;\n+\t\t\t\t}\n+\t\t    \t} \n+\t\t}\n+\n \t\texec(\"env\",\n \t\t\t\"GIT_AUTHOR_NAME=$author\",\n \t\t\t\"GIT_AUTHOR_EMAIL=$author\",\n"},{"id":"7357","messageId":"20050816110725.GL11882MdfPADPa@garage.linux.student.kuleuven.ac.be","threadId":"1533","inReplyTo":"20050816103527.F420A33010C@ng.eduforge.org","subject":"Re: [PATCH] Add merge detection to git-cvsimport","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2005-08-16T11:07:25Z","receivedAt":"2005-08-16T11:07:25Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Tue, Aug 16, 2005 at 10:35:27PM +1200, Martin Langhoff wrote:\n> +\n> +sub get_headref($$) {\n\nIf you want to check whether a ref is valid, then\nit is better to use git-rev-parse...\n\n> +    my $name    = shift;\n> +    my $git_dir = shift; \n> +    my $sha;\n> +    \n> +    if (open(C,\"$git_dir/refs/heads/$name\")) {\n> +\tchomp($sha = <C>);\n> +\tclose(C);\n> +\tlength($sha) == 40\n> +\t    or die \"Cannot get head id for $name ($sha): $!\\n\";\n\n... but if you're just going to die, then why not simply\nlet git-commit-tree do the test ?\n\n> +\t\t\t\tif ($mparent eq 'HEAD') { $mparent = 'origin'};\n\nPlease don't hardcode 'origin' here.\n\nskimo\n"},{"id":"7387","messageId":"46a038f9050816143646fa4137@mail.gmail.com","threadId":"1533","inReplyTo":"20050816110725.GL11882MdfPADPa@garage.linux.student.kuleuven.ac.be","subject":"Re: [PATCH] Add merge detection to git-cvsimport","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2005-08-16T21:36:08Z","receivedAt":"2005-08-16T21:36:08Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 8/16/05, Sven Verdoolaege <skimo@kotnet.org> wrote:\n> On Tue, Aug 16, 2005 at 10:35:27PM +1200, Martin Langhoff wrote:\n> > +\n> > +sub get_headref($$) {\n> \n> If you want to check whether a ref is valid, then\n> it is better to use git-rev-parse...\n\nWe are reading/writing directly to .git/refs/heads/ a lot in this\nscript. Not changing that for the time being.\n\n> > +    if (open(C,\"$git_dir/refs/heads/$name\")) {\n> > +     chomp($sha = <C>);\n> > +     close(C);\n> > +     length($sha) == 40\n> > +         or die \"Cannot get head id for $name ($sha): $!\\n\";\n> \n> ... but if you're just going to die, then why not simply\n> let git-commit-tree do the test ?\n\nBecause we get the head names from cvsps output, and we want to have a\nspecific error when cvsps has given us a bogus branch name.\ngit-commit-tree could fail for a number of reasons, this one is the\nmost likely one to be from a bug in cvsps or the cvsimport logic.\n \n> > +                             if ($mparent eq 'HEAD') { $mparent = 'origin'};\n> \n> Please don't hardcode 'origin' here.\n\nDuh! Patch submitted. Juniooooo! \n\n\nmartin\n"},{"id":"7451","messageId":"pan.2005.08.17.17.29.26.687298@smurf.noris.de","threadId":"1533","inReplyTo":"46a038f9050816143646fa4137@mail.gmail.com","subject":"Re: [PATCH] Add merge detection to git-cvsimport","fromName":"Matthias Urlichs","fromEmail":"smurf@smurf.noris.de","sentAt":"2005-08-17T17:29:28Z","receivedAt":"2005-08-17T17:29:28Z","isPatch":true,"sender":{"key":"matthias@urlichs.de","avatar":"https://gravatar.com/avatar/2708905af227313eba6f2b2ae0f7d0259b5ac5d71baef58fe5a13c699ce0bbf0?d=mp&s=160"},"body":"Hi, Martin Langhoff wrote:\n\n> this one is the\n> most likely one to be from a bug in cvsps or the cvsimport logic.\n\nThat's not a bug in the import logic, just a failure of the CVS-merging\nperson to be consistent. (Which is hardly news. :-/ )\n\n-- \nMatthias Urlichs   |   {M:U} IT Design @ m-u-it.de   |  smurf@smurf.noris.de\nDisclaimer: The quote was selected randomly. Really. | http://smurf.noris.de\n - -\nReason:\n\tBad, toxic entity, that foolish people use when they ought to use\n\ttheir inner voice, or angels, or intuition, or a gut feeling, or\n\ttheir hearts, or the I Ching.\n\t\t-- Fashionable Dictionary (www.butterfliesandwheels.com)\n"}]}