使用git-svn处理SVN关键字扩展 [英] Dealing with SVN keyword expansion with git-svn

查看:112
本文介绍了使用git-svn处理SVN关键字扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近问到在Git中扩展关键字,并且我愿意接受这个设计在Git中不会真的支持这个想法。



无论好还是坏,我目前正在开发的项目都需要像这样的SVN关键字扩展:

  svn propset svn:keywordsIdexpl3.dtx 

保持这个字符串是最新的:

  $ Id:expl3.dtx 803 2008-09-11 14:01 :58Z将$ 

但我很想使用Git来执行我的版本控制。不幸的是,根据文档,git-svn不支持这一点:
$ b


我们忽略除svn之外的所有SVN属性:可执行文件


但是通过一些前/后提交钩子来模拟这个关键字似乎并不太棘手。我是第一个想要这个的人吗?有没有人有这样的代码?

解决方案

这里发生了什么:Git经过优化,尽可能快地在分支之间切换。特别是, git checkout 旨在不触及任何两个分支都相同的文件。



不幸的是,RCS关键字替换打破了这个例如,在切换分支时,使用 $ Date $ 需要 git checkout 来触摸树中的每个文件。对于一个与Linux内核大小相同的存储库来说,这会让所有的事情停下来。



一般来说,最好的办法是标记至少一个版本:

  $ git tag v0.5.whatever 

...然后从你的Makefile中调用下面的命令:
$ b $ $ $ $ g $ describe $ - -tags
v0.5.15.1-6-g61cde1d

在这里,git告诉我我正在使用匿名版本6提交v0.5.15.1,其中SHA1哈希以 g61cde1d 开头。如果您将此命令的输出粘贴到某个地方的 *。h 文件中,那么您已经开始工作了,并且将发布的软件链接回源代码也没有问题。这是做事的首选方式。



如果您无法避免使用RCS关键字,您可能需要从 Lars Hjemli的解释。基本上, $ Id $ 非常简单,如果你使用 git archive ,你也可以使用 $ Format $



但是,如果您完全无法避免使用RCS关键字, p>

  git config filter.rcs-keyword.clean'perl -pes / \\\\ $ Date [^ \ \\ $] * \\\\ $ $ \\\\ $ Date \\\ $ /'
git config filter.rcs-keyword.smudge'perl -pe s / \\\\ $ Date [^ \\\\ $] * \\\\ $ / \\\\ $ $ Date:`date`\\\\ $ $ / '

echo'$ Date $'> test.html
echo'test.html filter = rcs-keyword'>> .gitattributes
git add test.html .gitattributes
git commit -m实验RCS关键字支持git

rm test.html
git checkout test.html
cat test.html

在我的系统中,我得到:

  $日期:9月16日10:15:02 EDT 2008 $ 

如果您在 smudge clean 命令来工作,只需编写自己的Perl脚本来分别扩展和删除RCS关键字,并将这些脚本用作过滤器。



请注意,您真的不希望为绝对必要的文件执行此操作,否则git将失去大部分速度。


I recently asked about keyword expansion in Git and I'm willing to accept the design not to really support this idea in Git.

For better or worse, the project I'm working on at the moment requires SVN keyword expansion like this:

svn propset svn:keywords "Id" expl3.dtx

to keep this string up-to-date:

$Id: expl3.dtx 803 2008-09-11 14:01:58Z will $

But I would quite like to use Git to do my version control. Unfortunately, git-svn doesn't support this, according to the docs:

"We ignore all SVN properties except svn:executable"

But it doesn't seem too tricky to have this keyword stuff emulated by a couple of pre/post commit hooks. Am I the first person to want this? Does anyone have some code to do this?

解决方案

What's going on here: Git is optimized to switch between branches as quickly as possible. In particular, git checkout is designed to not touch any files that are identical in both branches.

Unfortunately, RCS keyword substitution breaks this. For example, using $Date$ would require git checkout to touch every file in the tree when switching branches. For a repository the size of the Linux kernel, this would bring everything to a screeching halt.

In general, your best bet is to tag at least one version:

$ git tag v0.5.whatever

...and then call the following command from your Makefile:

$ git describe --tags
v0.5.15.1-6-g61cde1d

Here, git is telling me that I'm working on an anonymous version 6 commits past v0.5.15.1, with an SHA1 hash beginning with g61cde1d. If you stick the output of this command into a *.h file somewhere, you're in business, and will have no problem linking the released software back to the source code. This is the preferred way of doing things.

If you can't possibly avoid using RCS keywords, you may want to start with this explanation by Lars Hjemli. Basically, $Id$ is pretty easy, and you if you're using git archive, you can also use $Format$.

But, if you absolutely cannot avoid RCS keywords, the following should get you started:

git config filter.rcs-keyword.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'
git config filter.rcs-keyword.smudge 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date: `date`\\\$/"'

echo '$Date$' > test.html
echo 'test.html filter=rcs-keyword' >> .gitattributes
git add test.html .gitattributes
git commit -m "Experimental RCS keyword support for git"

rm test.html
git checkout test.html
cat test.html

On my system, I get:

$Date: Tue Sep 16 10:15:02 EDT 2008$

If you have trouble getting the shell escapes in the smudge and clean commands to work, just write your own Perl scripts for expanding and removing RCS keywords, respectively, and use those scripts as your filter.

Note that you really don't want to do this for more files than absolutely necessary, or git will lose most of its speed.

这篇关于使用git-svn处理SVN关键字扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆