使用Git SVN当模拟subwcrev [英] Emulate subwcrev when using git-svn

查看:775
本文介绍了使用Git SVN当模拟subwcrev的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git-svn的与包含一些C ++项目现有的SVN仓库进行交互。 subwcrev.exe用作pre-生成事件以更新的C ++头(svnversion.h)一些字符串。这些字符串得到hardcompiled,形成生成的二进制文件的一些版本信息。

I use git-svn to interact with an existing SVN repository that contains some C++ projects. subwcrev.exe is used as a pre-build event to update some strings in a C++ header (svnversion.h). These strings get hardcompiled to form some version information for the resulting binary.

由于subwcrev要求.svn文件元数据来工作时,pre-生成事件是怎么回事混帐svn的工作拷贝使用时失败。所以,我想出了我作为后提交和我的git仓库结帐后钩子使用下面的bash脚本。该脚本尝试基础上,混帐SVN信息(在本地文件缓存)的输出做同样的事情subwcrev。

Since subwcrev requires .svn metadata to work, the pre-build event is going to fail when used on the git-svn working copy. So I came up with the following bash script which I use as post-commit and post-checkout hooks for my git repository. The script tries to do the same thing as subwcrev based on the output of git svn info (cached in a local file).

#!/bin/sh
if [ ! -f svninfo ] ; then
    git svn info > svninfo
fi

revision=`sed -e "/Revision/!d" -e "s/Revision: \(.*\)/\1/" svninfo`
lastchange=`sed -e "/Last Changed Rev/!d" -e "s/Last Changed Rev: \(.*\)/\1/" svninfo`
# Get the last changed date, extract timestamp, replaces dashes with slashes
changedate=`sed -e "/Last Changed Date/!d" -e "s/Last Changed Date: \(.\{19\}\).*/\1/" -e "s!-!\\\\\\/!g" svninfo`
now=`date "+%Y\/%m\/%d %H:%M:%S"`

gitcommit=`git show --abbrev-commit | sed -n -e "s/commit //p"`

for entry in $( find -name svnversion_template.h ); do
    newname=`echo $entry|sed -e "s/_template//"`
    sed -e "s/\\\$WCRANGE\\\$/${revision}/" \
        -e "s/\\\$WCREV\\\$/${lastchange}-${gitcommit}/" \
        -e "s/\\\$WCDATE\\\$/${changedate}/" \
        -e "s/\\\$WCNOW\\\$/${now}/" \
        -e "s/\\\$WCURL\\\$/local git repo/" \
        -e "s/\\\$WCMODS.*\\\$/(true)/" \
        -e "s/\\\$WCMIXED.*\\\$/(false)/" \
        $entry > `echo $entry|sed -e "s/_template//"`
done

我真的不能效仿迄今已是自动检测本地未提交的修改(基于最后检出的SVN版本),使subwcrev非常有用。

What I cannot really emulate so far is the automatic detection of a local uncommitted changes (based on the last checked out SVN revision) that makes subwcrev so useful.

我将 $ WCREV $ 与SVN库的版本号(如subwcrev会做),但这次我加我的缩写git的承诺哈希值来确定code口编译。我现在的问题是:有没有办法在shell脚本我现在头是否从上次读取SVN版本不同,这样我就可以省略添加来区分 - $ {gitcommit} 部分,设置 $ WCMODS $ 来假的?

I am replacing $WCREV$ with the revision number of the SVN repository (as subwcrev would do) but this time I add my abbreviated git commit hash to identify the code I compiled. My question now is: Is there a way to distinguish in a shell script whether my current HEAD differs from the last fetched SVN revision so that I could omit adding the -${gitcommit} part and set $WCMODS$ to false?

如果有一些东西像后混帐svn的dcommit挂钩,我的问题将得到解决,也自那时起特殊的钩子将创建svnversion,如果。 ^ h不同。可以这样钩以某种方式加入?

If there were some thing like a post-"git svn dcommit" hook, my problem would be solved, too, since then that special hook would create the svnversion.h differently. Can such hook be added somehow?

推荐答案

所以看起来你可能有解析混帐SVN信息内容查询自己获得什么是通常存储在WCREV。这个例子的结果是这样对我来说:

So it looks like you might have to parse the contents of the git svn info query yourself to get what is normally stored in WCREV. The example results look like this for me:

git svn info
Path: .
URL: http://myurl.com/trunk/myrepo
Repository Root: http://myurl.com
Repository UUID: 15fed3e9-81ce-ef4a-a7da-fc36e3df1edc
Revision: 14106
Node Kind: directory
Schedule: normal
Last Changed Author: myusername
Last Changed Rev: 14106
Last Changed Date: 2015-05-29 10:23:10 -0400 (Fri, 29 May 2015)

现在你问题的第二部分,你是否可以判断你的git的HEAD最新的svn签相符,你需要使用命令 git的差异混帐svn的命令。 混帐svn的这里就是混帐svn的是保持分支的名称,如果一切都是最新的,其结果将是空的。

Now for the second part of your question, whether or not you can tell if your git HEAD matches the latest svn checkout, you'll need to use the command git diff git-svn command. "git-svn" here is the name of the branch that the git-svn program is maintaining, and if everything is up to date, the results will be empty.

这篇关于使用Git SVN当模拟subwcrev的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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