3

I am using a benchmark environment to run performance tests on the working copy of trunk of company's code repository.

We have a large ant build file which manages the whole testing process (build database with sample data; build, deploy and run the product; build, deploy and run the grinder and monitoring tools; sampling various types of information). In the process there are two steps related to SVN:

  1. When building the product, the benchmark ant script calls the ant build file in the working copy, and svn info is called in a custom task to get the current revision number of the local working copy (from "The current revision is: 12345" line in the output), which will be used later to name the log-archive file.
  2. When starting sampling, the benchmark ant script will first run svn info, svn status, svn diff in the working copy directory and save the outputs to log files.

Now other people want the benchmark ant script can also support git. So that the script should check if it is svn or git (this step is easy), and then run commands to collect version control information accordingly (confused with this step).

So my question is:

  • What is the similar and different points between svn revision and git revision?
  • What should I use to get the revision "number" in git (I know it's not a number) like what I do in "1" above??? Is it git branch -v?
  • What should I use in git to get as much information as I can get using svn, like what I do in "2" above??? Is git remote -v, git branch -v, git log --max-count=1, git status, git diff enough?
  • How can I use git diff to generate a diff file that can be used both in git and svn, as well as in other editors that supports to apply a diff?

Thanks.

m0tive
  • 2,796
  • 1
  • 22
  • 36
Dante WWWW
  • 2,729
  • 1
  • 17
  • 33
  • 1
    you might find this useful http://stackoverflow.com/questions/1042280/is-there-a-subversion-users-guide-to-git – m0tive Dec 20 '11 at 09:53
  • also, if you're checking if a directory is inside a git repo, a good way is with `git re-parse --is-inside-work-tree` rather than just looking for a `.git` directory. – m0tive Dec 20 '11 at 10:22

2 Answers2

4
  1. What are the main differences?

    This covers some of the differences: http://git.or.cz/course/svn.html#commit

  2. What should I use to get the revision "number" in git?

    git rev-parse HEAD
    

    This converts the HEAD tag into the revision's hash.

  3. Is git remote -v, git branch -v, git log --max-count=1, git status, git diff enough?

    I guess that depends on what info you need. That should cover most of the output from svn info, svn status and svn diff.

  4. How can I use git diff to generate a diff file that can be used both in git and svn?

    git diff -p > a.diff will create a standard unified diff. Svn does not handle patches in a normal way (git can usually read an svn-generated patch). This might help you convert into svn patch format: Git format-patch to be svn compatible?

Community
  • 1
  • 1
m0tive
  • 2,796
  • 1
  • 22
  • 36
  • Upvote for answering each point. Thank you for your effort. For 2, is that the revision for the local repo? We need the revision because we need to know on which revision we build our product so that we can review the code changes later. For 4, since the whole process of testing is handled automatically by the ant script, and we generate more than 10 testing archive everyday, it is better if there is anyway to convert the diff file automatically. However, looks like there isn't a good/automatical way to make the diff compatible (although it should be SVN's fault)... – Dante WWWW Dec 21 '11 at 01:54
  • Also, for the patching thing, if there is not any way to solve, we can accept that the patch is only compitable for the version control system that the tester is using. – Dante WWWW Dec 21 '11 at 02:02
  • (2) Yes, `HEAD` is the current checked out, so doing `git rev-parse HEAD` with get you the hash id for the current commit. (4) This script might work for you: https://gist.github.com/721622 I think I got it working previously, but never on any real work. – m0tive Dec 22 '11 at 15:13
  • gist.github.com/1520442 I found that the function/class descriptions in hunk header is preventing SmartSVN from recognizing the diff file. So I forked the script and made a little change. Will that be safe? – Dante WWWW Dec 26 '11 at 02:59
0

As for the revision for release part, common practice for git is using combination of git tag -a x.x.x and git describe

Say, when you're ready to tag your build, you can do git tag -a 1.0.0 then you pushed the tags to the origin repo by git push --tags, after you committed another 5 commits, git describe will return something like 1.0.0-5-g13f0e88 which you can use as your version string.

number5
  • 15,913
  • 3
  • 54
  • 51