带有svn用户名的git svn dcommit
我试图在一个旧的subversion存储库上使用git。我们有多个用户在处理新的git remote(origin/master),它是旧的repo的git svn克隆。问题是,当我们执行git svn dcommit将更改从新的git repo推送到旧的subversion repo时,提交者的用户名将丢失,取而代之的是git svn克隆用户的信息。有没有办法在提交数据时将提交人的信息保存到subversion中?要求每个人使用“签准人”或其他方式在每次提交的消息中包含用户名。这是一个相当丑陋的解决方案,但如果不破解git svn源代码,这是唯一可以做的事情。Github将一如既往地进行拯救!他们对git svn的快速概述涉及到用户映射:带有svn用户名的git svn dcommit,svn,git,migration,Svn,Git,Migration,我试图在一个旧的subversion存储库上使用git。我们有多个用户在处理新的git remote(origin/master),它是旧的repo的git svn克隆。问题是,当我们执行git svn dcommit将更改从新的git repo推送到旧的subversion repo时,提交者的用户名将丢失,取而代之的是git svn克隆用户的信息。有没有办法在提交数据时将提交人的信息保存到subversion中?要求每个人使用“签准人”或其他方式在每次提交的消息中包含用户名。这是一个相当丑陋
基本上,您可以创建一个包含所需映射的文件。您可以将git svn与
--从添加作者和--使用日志作者一起使用。前者表示提交消息中From:
行中的git作者,后者执行反向转换
也就是说,subversion存储库格式比git存储库格式差。它不支持合并,也不支持提交者与作者之间的冲突,也不支持与推送时间不同的提交时间。git svn可以在本地获取git ui,但它不能对数据模型做太多工作。希望您能够迁移到git存储库,可能有一个svn前端(现在有和github的封闭源代码选项)。我知道这是一个非常古老的主题,但如果有人感兴趣,我将此技巧添加到我的git svn本地副本中:
23a24
> use POSIX qw/strftime/;
984a986
> my $ra = Git::SVN::Ra->new($url);
987c989
< ra => Git::SVN::Ra->new($url),
---
> ra => $ra,
995a998,1014
> my $cmt_author = get_commit_entry($d)->{author};
> my $cmt_date = get_commit_entry($d)->{date};
> if ( defined $cmt_author ) {
> foreach my $key ( keys %users ) {
> my $i = index($cmt_author, $users{$key}[1]);
> if ( $i != -1 ) {
> print "Changed author to $key\n";
> $ra->change_rev_prop($cmt_rev, 'svn:author', $key);
> last;
> }
> }
> }
> if ( defined $cmt_date ) {
> $cmt_date = strftime("%Y-%m-%dT%H:%M:%S.000000Z", gmtime($cmt_date));
> print "Changed date to $cmt_date\n";
> $ra->change_rev_prop($cmt_rev, 'svn:date', $cmt_date);
> }
1758c1777
< my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish) );
---
> my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish), author => undef, date => undef );
1768a1788
> my $date;
1774c1794,1797
< $author = $1 if (/^author (.*>)/);
---
> if (/^author (.*>) (\d+) ([\-\+]?\d+)$/o) {
> $author = $1;
> $date = Git::SVN::Log::parse_git_date($2, $3);
> }
1792a1816,1817
> $log_entry{author} = $author || undef;
> $log_entry{date} = $date || undef;
23a24
>使用POSIXQW/strftime/;
984a986
>我的$ra=Git::SVN::ra->new($url);
987c989
Git::SVN::ra->new($url),
---
>ra=>$ra,
995A9981014
>my$cmt\u author=get\u commit\u条目($d)->{author};
>my$cmt\u date=获取提交条目($d)->{date};
>if(定义为$cmt\U作者){
>foreach my$密钥(密钥%users){
>my$i=index($cmt_author,$users{$key}[1]);
>如果($i!=-1){
>打印“已将作者更改为$key\n”;
>$ra->change\u rev\u prop($cmt\u rev,'svn:author',$key);
>最后;
> }
> }
> }
>如果(定义为$cmt\U日期){
>$cmt_date=strftime(%Y-%m-%dT%H:%m:%S.000000Z),gmtime($cmt_date));
>打印“更改日期为$cmt\U日期\n”;
>$ra->change\u rev\u prop($cmt\u rev,'svn:date',$cmt\u date);
> }
1758c1777
'',tree=>从树中获取树($treeish));
---
>我的%log\u条目=(log=>'',tree=>get\u tree\u from\u treeish($treeish),author=>undef,date=>undef);
1768a1788
>我的$date;
1774C17941797
<$author=$1如果(/^author(.*>)/);
---
>如果(/^author(.*>)(\d+)([\-\+]?\d+)$/o){
>$author=$1;
>$date=Git::SVN::Log::parse_Git_date($2,$3);
> }
1792A18161817
>$log_entry{author}=$author | | unde;
>$log_entry{date}=$date | | undef;
这是针对1.9.1-1(ubuntu14.04上的deb包版本)。它是不可配置的,从这个意义上说,如果你有一个users.txt文件,它将使用它,它将始终尝试设置日期。此外,如果您有多个SVN帐户为一个给定的git用户,它只会选择一个
我只是刚刚开始在愤怒中使用它,但我想它可能会起作用,祈祷好运
问候
Adam我对提出的补丁做了一点修改,以便git svn dcommit
接受--commit author
选项:
--- ./git-svn.orig 2014-10-09 23:11:40.032767542 +0300
+++ ./git-svn 2014-10-09 23:27:58.252753020 +0300
@@ -116,7 +116,7 @@
$_before, $_after,
$_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
$_prefix, $_no_checkout, $_url, $_verbose,
- $_commit_url, $_tag, $_merge_info, $_interactive);
+ $_commit_url, $_commit_author, $_tag, $_merge_info, $_interactive);
# This is a refactoring artifact so Git::SVN can get at this git-svn switch.
sub opt_prefix { return $_prefix || '' }
@@ -194,6 +194,7 @@
'dry-run|n' => \$_dry_run,
'fetch-all|all' => \$_fetch_all,
'commit-url=s' => \$_commit_url,
+ 'commit-author=s' => \$_commit_author,
'revision|r=i' => \$_revision,
'no-rebase' => \$_no_rebase,
'mergeinfo=s' => \$_merge_info,
@@ -982,6 +983,7 @@
$rewritten_parent);
}
+ my $ra = Git::SVN::Ra->new($url);
my %ed_opts = ( r => $last_rev,
log => get_commit_entry($d)->{log},
ra => $ra,
@@ -993,6 +995,10 @@
editor_cb => sub {
print "Committed r$_[0]\n";
$cmt_rev = $_[0];
+ if (defined($_commit_author)) {
+ print "Changed author to $_commit_author\n";
+ $ra->change_rev_prop($cmt_rev, 'svn:author', $_commit_author);
+ }
},
mergeinfo => $_merge_info,
svn_path => '');
@@ -1790,6 +1796,7 @@
}
print $log_fh $msgbuf or croak $!;
command_close_pipe($msg_fh, $ctx);
+ $log_entry{author} = $author || undef;
}
close $log_fh or croak $!;
这是亚当·萨顿答案的另一个稍加修改的版本
它从authors文件创建反向映射,并对重复和/或丢失的authors进行额外检查。
它还会在输入中告诉您每次提交时哪个Git用户映射到哪个SVN用户,即使在运行Git SVN dcommit--dry run时也是如此
[root@qa-travel-centos git-svn-bridge]# diff scripts/git-svn.orig scripts/git-svn.hacked
23a24
> use POSIX;
963a965,975
>
> #Revert the keys/values from authors into a reverse map.
> #If a duplicate is found(i.e. 2 git users matching 1 svn user) abort the operation.
> my %rev_author_map;
> while (my ($key, @value) = each %users) {
> my $rev_key="$value[0][0] <$value[0][1]>";
> if(exists $rev_author_map{$rev_key}) {
> fatal "Found a duplicate GIT author($rev_key) in the authorsfile. Aborting dcommit!"
> }
> $rev_author_map{$rev_key}=$key
> }
972a985,997
> my $commit_entry = get_commit_entry($d);
> my $cmt_author = $commit_entry->{author};
> my $cmt_date = $commit_entry->{date};
> print "GIT AUTHOR: $cmt_author; \n";
> if(defined $cmt_author) {
> my $svn_author = $rev_author_map{$cmt_author};
> #Here we check if the git commit author matches an author in the authorsfile
> if ((not (defined $svn_author)) || $svn_author eq "") {
> fatal "The git author: $cmt_author was not found in the authors file. Make sure you have commited as a user listed in the authors file. Note:matching is case sensitive.";
> }
> print "SVN AUTHOR: $svn_author\n";
> }
>
984c1009
<
---
> my $ra = Git::SVN::Ra->new($url);
987c1012
< ra => Git::SVN::Ra->new($url),
---
> ra => $ra,
995a1021,1032
> #Here we coerce SVN into accepting the correct user according to the reverse mapping.
> if(defined $cmt_author) {
> my $svn_author = $rev_author_map{$cmt_author};
> print "SVN AUTHOR: $svn_author\n";
> $ra->change_rev_prop($cmt_rev, 'svn:author', $svn_author)
> }
> #Here we coerce SVN into accepting the commit date from Git.
> if ( defined $cmt_date ) {
> $cmt_date = strftime("%Y-%m-%dT%H:%M:%S.000000Z", gmtime($cmt_date));
> print "SVN DATE SET TO: $cmt_date\n";
> $ra->change_rev_prop($cmt_rev, 'svn:date', $cmt_date);
> }
1748c1785
< my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish) );
---
> my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish), author =>undef, date => undef );
1758a1796
> my $date;
1764c1802,1805
< $author = $1 if (/^author (.*>)/);
---
> if(/^author (.*>) (\d+) ([\-\+]?\d+)$/o){
> $author = $1;
> $date = $2;
> }
1782a1824,1825
> $log_entry{author} = $author || undef;
> $log_entry{date} = $date || undef;
[root@qa-travel centos git svn bridge]#差异脚本/git-svn.orig脚本/git-svn.hacked
23a24
>使用POSIX;
963A965975
>
>#将作者提供的键/值还原为反向映射。
>#如果发现重复项(即2个git用户与1个svn用户匹配),则中止操作。
>我的%rev\u作者\u地图;
>while(my($key,@value)=每个%users){
>my$rev_key=“$value[0][0]”;
>if(存在$rev_author_map{$rev_key}){
>致命“在authorsfile中发现重复的GIT作者($rev_key)。正在中止dcommit!”
> }
>$rev_author_map{$rev_key}=$key
> }
972A985997
>my$commit\u entry=get\u commit\u entry($d);
>my$cmt\u author=$commit\u entry->{author};
>my$cmt_date=$commit_entry->{date};
>打印“GIT AUTHOR:$cmt\u AUTHOR;\n”;
>if(定义为$cmt\U作者){
>我的$svn_author=$rev_author_map{$cmt_author};
>#这里我们检查git提交作者是否与authorsfile中的作者匹配
>if((未定义为$svn_author))| |$svn_author eq“”){
>致命“git author:$cmt_author未在authors文件中找到。请确保您已作为authors文件中列出的用户提交。注意:匹配区分大小写。”;
> }
>打印“SVN作者:$SVN\U作者\n”;
> }
>
984c1009
<
---
>我的$ra=Git::SVN::ra->new($url);
987c1012
<