{"thread":{"id":"20968","subject":"[PATCH] Initial manually svn property setting support for git-svn","startedAt":"2009-09-16T07:02:09Z","lastAt":"2009-09-23T08:58:12Z","messageCount":3,"participants":["David Fraser","Thiago Farina","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"123339","messageId":"1927112650.1281253084529659.JavaMail.root@klofta.sjsoft.com","threadId":"20968","inReplyTo":"1482075216.1261253084509966.JavaMail.root@klofta.sjsoft.com","subject":"[PATCH] Initial manually svn property setting support for git-svn","fromName":"David Fraser","fromEmail":"davidf@sjsoft.com","sentAt":"2009-09-16T07:02:09Z","receivedAt":"2009-09-16T07:02:09Z","isPatch":true,"sender":{"key":"davidf@sjsoft.com","avatar":null},"body":"This basically stores an attribute 'svn-properties' for each file that needs them changed, and then sets the properties when committing.\n\nIssues remaining:\n * The way it edits the .gitattributes file is suboptimal - it just appends to the end the latest version\n * It could use the existing code to get the current svn properties to see if properties need to be changed; but this doesn't work on add\n * It would be better to cache all the svn properties locally - this could be done automatically in .gitattributes but I'm not sure everyone would want this, etc\n * No support for deleting properties\n\nUsage is:\n git svn propset PROPNAME PROPVALUE PATH\n\nAdded minimal documentation for git-svn propset\n\nSigned-off-by: David Fraser <davidf@sjsoft.com>\n---\n Documentation/git-svn.txt |    5 ++\n git-svn.perl              |   95 ++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 99 insertions(+), 1 deletions(-)\n\n\n>From 521ed4fc7c877269fb029b9494ef57300c722a10 Mon Sep 17 00:00:00 2001\nFrom: David Fraser <davidf@sjsoft.com>\nDate: Wed, 16 Sep 2009 13:28:00 +0200\nSubject: [PATCH] Initial manually svn property setting support for git-svn.\n\nThis basically stores an attribute 'svn-properties' for each file that needs them changed, and then sets the properties when committing.\n\nIssues remaining:\n * The way it edits the .gitattributes file is suboptimal - it just appends to the end the latest version\n * It could use the existing code to get the current svn properties to see if properties need to be changed; but this doesn't work on add\n * It would be better to cache all the svn properties locally - this could be done automatically in .gitattributes but I'm not sure everyone would want this, etc\n * No support for deleting properties\n\nUsage is:\n git svn propset PROPNAME PROPVALUE PATH\n\nAdded minimal documentation for git-svn propset\n\nSigned-off-by: David Fraser <davidf@sjsoft.com>\n---\n Documentation/git-svn.txt |    5 ++\n git-svn.perl              |   95 ++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 99 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex 1812890..b14bcf0 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -345,6 +345,11 @@ Any other arguments are passed directly to 'git log'\n \tGets the Subversion property given as the first argument, for a\n \tfile.  A specific revision can be specified with -r/--revision.\n \n+'propset'::\n+\tSets the Subversion property given as the first argument, to the value\n+        given as the second argument, for files specifed as the remaining\n+\targuments. The property will be sent with the next commit.\n+\n 'show-externals'::\n \tShows the Subversion externals.  Use -r/--revision to specify a\n \tspecific revision.\ndiff --git a/git-svn.perl b/git-svn.perl\nindex e0ec258..aaf92fb 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -80,7 +80,7 @@ my ($_stdin, $_help, $_edit,\n \t$_version, $_fetch_all, $_no_rebase, $_fetch_parent,\n \t$_merge, $_strategy, $_dry_run, $_local,\n \t$_prefix, $_no_checkout, $_url, $_verbose,\n-\t$_git_format, $_commit_url, $_tag);\n+\t$_git_format, $_commit_url, $_tag, $_set_svn_props);\n $Git::SVN::_follow_parent = 1;\n $_q ||= 0;\n my %remote_opts = ( 'username=s' => \\$Git::SVN::Prompt::_username,\n@@ -147,6 +147,7 @@ my %cmd = (\n \t\t\t  'dry-run|n' => \\$_dry_run,\n \t\t\t  'fetch-all|all' => \\$_fetch_all,\n \t\t\t  'commit-url=s' => \\$_commit_url,\n+\t\t\t  'set-svn-props=s' => \\$_set_svn_props,\n \t\t\t  'revision|r=i' => \\$_revision,\n \t\t\t  'no-rebase' => \\$_no_rebase,\n \t\t\t%cmt_opts, %fc_opts } ],\n@@ -171,6 +172,9 @@ my %cmd = (\n         'propget' => [ \\&cmd_propget,\n \t\t       'Print the value of a property on a file or directory',\n \t\t       { 'revision|r=i' => \\$_revision } ],\n+        'propset' => [ \\&cmd_propset,\n+\t\t       'Set the value of a property on a file or directory - will be set on commit',\n+\t\t       {} ],\n         'proplist' => [ \\&cmd_proplist,\n \t\t       'List all properties of a file or directory',\n \t\t       { 'revision|r=i' => \\$_revision } ],\n@@ -892,6 +896,64 @@ sub cmd_propget {\n \tprint $props->{$prop} . \"\\n\";\n }\n \n+sub check_attr\n+{\n+    my ($attr,$path) = @_;\n+    if ( open my $fh, '-|', \"git\", \"check-attr\", $attr, \"--\", $path )\n+    {\n+\tmy $val = <$fh>;\n+\tclose $fh;\n+\t$val =~ s/^[^:]*:\\s*[^:]*:\\s*(.*)\\s*$/$1/;\n+\treturn $val;\n+    }\n+    else\n+    {\n+\treturn undef;\n+    }\n+}\n+\n+# cmd_propset (PROPNAME, PROPVAL, PATH)\n+# ------------------------\n+# Adjust the SVN property PROPNAME to PROPVAL for PATH.\n+sub cmd_propset {\n+\tmy ($propname, $propval, $path) = @_;\n+\t$path = '.' if not defined $path;\n+\t$path = $cmd_dir_prefix . $path;\n+\tusage(1) if not defined $propname;\n+\tusage(1) if not defined $propval;\n+\tmy $file = basename($path);\n+\tmy $dn = dirname($path);\n+\tmy $current_properties = check_attr( \"svn-properties\", $path );\n+\tmy $new_properties = \"\";\n+\tif ($current_properties eq \"unset\" || $current_properties eq \"\" || $current_properties eq \"set\") {\n+\t\t$new_properties = \"$propname=$propval\";\n+\t} else {\n+\t\t# TODO: handle combining properties better\n+\t\tmy @props = split(/;/, $current_properties);\n+\t\tmy $replaced_prop = 0;\n+\t\tforeach my $prop (@props) {\n+\t\t\t# Parse 'name=value' syntax and set the property.\n+\t\t\tif ($prop =~ /([^=]+)=(.*)/) {\n+\t\t\t\tmy ($n,$v) = ($1,$2);\n+\t\t\t\tif ($n eq $propname)\n+\t\t\t\t{\n+\t\t\t\t\t$v = $propval;\n+\t\t\t\t\t$replaced_prop = 1;\n+\t\t\t\t}\n+\t\t\t\tif ($new_properties eq \"\") { $new_properties=\"$n=$v\"; }\n+\t\t\t\telse { $new_properties=\"$new_properties;$n=$v\"; }\n+\t\t\t}\n+\t\t}\n+\t\tif ($replaced_prop eq 0) {\n+\t\t\t$new_properties = \"$new_properties;$propname=$propval\";\n+\t\t}\n+\t}\n+\tmy $attrfile = \"$dn/.gitattributes\";\n+\topen my $attrfh, '>>', $attrfile or die \"Can't open $attrfile: $!\\n\";\n+\t# TODO: don't simply append here if $file already has svn-properties\n+\tprint $attrfh \"$file svn-properties=$new_properties\\n\";\n+}\n+\n # cmd_proplist (PATH)\n # -------------------\n # Print the list of SVN properties for PATH.\n@@ -4185,6 +4247,33 @@ sub apply_autoprops {\n \t}\n }\n \n+sub apply_manualprops {\n+\tmy ($self, $file, $fbat) = @_;\n+\tmy $path = $cmd_dir_prefix . $file;\n+\tmy $pending_properties = ::check_attr( \"svn-properties\", $path );\n+\tif ($pending_properties eq \"\") { return; }\n+\t# Parse the list of properties to set.\n+\tmy @props = split(/;/, $pending_properties);\n+\t# TODO: get existing properties to compare to - this fails for add so currently not done\n+\t# my $existing_props = ::get_svnprops($file);\n+\tmy $existing_props = {};\n+\t# TODO: caching svn properties or storing them in .gitattributes would make that faster\n+\tforeach my $prop (@props) {\n+\t\t# Parse 'name=value' syntax and set the property.\n+\t\tif ($prop =~ /([^=]+)=(.*)/) {\n+\t\t\tmy ($n,$v) = ($1,$2);\n+\t\t\tfor ($n, $v) {\n+\t\t\t\ts/^\\s+//; s/\\s+$//;\n+\t\t\t}\n+\t\t\tif (defined $existing_props->{$n} && $existing_props->{$n} eq $v) {\n+\t\t\t\tmy $needed = 0;\n+\t\t\t} else {\n+\t\t\t\t$self->change_file_prop($fbat, $n, $v);\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n sub A {\n \tmy ($self, $m) = @_;\n \tmy ($dir, $file) = split_path($m->{file_b});\n@@ -4193,6 +4282,7 @@ sub A {\n \t\t\t\t\tundef, -1);\n \tprint \"\\tA\\t$m->{file_b}\\n\" unless $::_q;\n \t$self->apply_autoprops($file, $fbat);\n+\t$self->apply_manualprops($file, $fbat);\n \t$self->chg_file($fbat, $m);\n \t$self->close_file($fbat,undef,$self->{pool});\n }\n@@ -4204,6 +4294,7 @@ sub C {\n \tmy $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,\n \t\t\t\t$self->url_path($m->{file_a}), $self->{r});\n \tprint \"\\tC\\t$m->{file_a} => $m->{file_b}\\n\" unless $::_q;\n+\t$self->apply_manualprops($file, $fbat);\n \t$self->chg_file($fbat, $m);\n \t$self->close_file($fbat,undef,$self->{pool});\n }\n@@ -4223,6 +4314,7 @@ sub R {\n \tmy $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,\n \t\t\t\t$self->url_path($m->{file_a}), $self->{r});\n \tprint \"\\tR\\t$m->{file_a} => $m->{file_b}\\n\" unless $::_q;\n+\t$self->apply_manualprops($file, $fbat);\n \t$self->apply_autoprops($file, $fbat);\n \t$self->chg_file($fbat, $m);\n \t$self->close_file($fbat,undef,$self->{pool});\n@@ -4239,6 +4331,7 @@ sub M {\n \tmy $fbat = $self->open_file($self->repo_path($m->{file_b}),\n \t\t\t\t$pbat,$self->{r},$self->{pool});\n \tprint \"\\t$m->{chg}\\t$m->{file_b}\\n\" unless $::_q;\n+\t$self->apply_manualprops($file, $fbat);\n \t$self->chg_file($fbat, $m);\n \t$self->close_file($fbat,undef,$self->{pool});\n }\n-- \n1.6.0.4\n\n"},{"id":"123356","messageId":"a4c8a6d00909160918r77e418dbpe8debeff58d595c9@mail.gmail.com","threadId":"20968","inReplyTo":"1927112650.1281253084529659.JavaMail.root@klofta.sjsoft.com","subject":"Re: [PATCH] Initial manually svn property setting support for git-svn","fromName":"Thiago Farina","fromEmail":"tfransosi@gmail.com","sentAt":"2009-09-16T16:18:50Z","receivedAt":"2009-09-16T16:18:50Z","isPatch":true,"sender":{"key":"tfransosi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/970071?v=4"},"body":"On Wed, Sep 16, 2009 at 4:02 AM, David Fraser <davidf@sjsoft.com> wrote:\n> This basically stores an attribute 'svn-properties' for each file that needs them changed, and then sets the properties when committing.\n>\n> Issues remaining:\n>  * The way it edits the .gitattributes file is suboptimal - it just appends to the end the latest version\n>  * It could use the existing code to get the current svn properties to see if properties need to be changed; but this doesn't work on add\n>  * It would be better to cache all the svn properties locally - this could be done automatically in .gitattributes but I'm not sure everyone would want this, etc\n>  * No support for deleting properties\n>\n> Usage is:\n>  git svn propset PROPNAME PROPVALUE PATH\n>\n> Added minimal documentation for git-svn propset\n>\n> Signed-off-by: David Fraser <davidf@sjsoft.com>\n> ---\n>  Documentation/git-svn.txt |    5 ++\n>  git-svn.perl              |   95 ++++++++++++++++++++++++++++++++++++++++++++-\n>  2 files changed, 99 insertions(+), 1 deletions(-)\n>\nDavid, please read this, line 28:\nhttp://git.kernel.org/?p=git/git.git;a=blob;f=Documentation/SubmittingPatches;h=76fc84d8780762e083cd4ca584b9d783b8c0cd81;hb=HEAD\n\nPatches need to be send as plain text, not attached.\n"},{"id":"123666","messageId":"20090923085812.GA20673@dcvr.yhbt.net","threadId":"20968","inReplyTo":"1927112650.1281253084529659.JavaMail.root@klofta.sjsoft.com","subject":"Re: [PATCH] Initial manually svn property setting support for git-svn","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2009-09-23T08:58:12Z","receivedAt":"2009-09-23T08:58:12Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"David Fraser <davidf@sjsoft.com> wrote:\n> This basically stores an attribute 'svn-properties' for each file that\n> needs them changed, and then sets the properties when committing.\n\nHi David,\n\nPlease wrap your commit messages and emails at 72 columns or less.\nAll git svn code should be wrapped at 80 or less, too.\n\n> Issues remaining:\n>  * The way it edits the .gitattributes file is suboptimal - it just\n>  appends to the end the latest version\n\nConsider using $GIT_DIR/info/attributes or having an option to use that\ninstead.  Keeping a .gitattributes file in the git working tree but\n_out_ of SVN is important and required, but also difficult to get right.\n\nThere are users working on projects that frown upon using unsupported\nclients like git svn, and accidentally checking .gitattributes into\nthe project would likely annoy non-git users.  It's best to keep\n*.git* stuff outside of SVN projects unless they allow/want it.\n\nBut also you should not fail to consider the case that somebody else did\nintentionally commit .gitattributes into svn and you have little choice\nbut to commit your modifications to .gitattributes.  Things like\nmaintaining a mapping between svn:ignore and .gitignore has never\nhappened because of the corner cases that could pop up.\n\n>  * It could use the existing code to get the current svn properties to\n>  see if properties need to be changed; but this doesn't work on add\n\n>  * It would be better to cache all the svn properties locally - this\n>  could be done automatically in .gitattributes but I'm not sure\n>  everyone would want this, etc\n\nIt should be possible to infer/rebuild this by parsing unhandled.log\nfiles git svn generates by default.  There are definitely people who\ndon't want .gitattributes being written to automatically.\n\n>  * No support for deleting properties\n\nWhat advantage(s) does having this feature in git svn this give over\nusing:\n\n\tsvn prop(edit|set|del) ARGS $(git svn info --url)\n\nIn my experience, explicitly set properties are rarely-used so I\nneed to be convinced it's worth supporting in the future.\n\n> Usage is:\n>  git svn propset PROPNAME PROPVALUE PATH\n> \n> Added minimal documentation for git-svn propset\n\nWe'll also need a test case to ensure it continues working as other\nchanges get made and refactoring gets done.\n\n> +sub check_attr\n> +{\n> +    my ($attr,$path) = @_;\n\nPlease use formatting consistent with the rest of the file.  Always use\ntabs for indent here.\n\n> +    if ( open my $fh, '-|', \"git\", \"check-attr\", $attr, \"--\", $path )\n\nConsider command_output_pipe for better portability/consistency in\nGit.pm instead of open(my $fh, \"-|\", @args) which is Perl 5.8+-only.\n\n\nThanks for the effort and keep us informed of improvements you make.\n\n-- \nEric Wong\n"}]}