Can we see/get the svn commit ID/revision number in Bitbucket?

Hi,

we are using SVN Mirror to sync between SVN and Bitbucket, after syncing from svn to bitbucket we can see that the svn revision number replaced with git SHA number , so is there any way to see the svn revision number as well?

Thanks,
Manju NS

Hi,

not that the SVN revision number is replaced by SHA hash, it’s just that Git version control system does not use the revisions numeration approach SVN VCS is based upon and uses the SHA hashes as commits ids. So when SVN Mirror add-on translates a revision from SVN to Git, it creates a Git commit with its own SHA-1. The revision number of a commit that came from SVN can be kept, however, there are two way for that.

First is to use Git notes – SVN Mirror add-on stores the revision number in notes during the SVN-to-Git translation. The notes can be obtained in a working copy by adding the following to the Git configuration file in the working copy (.git/config):

    fetch = +refs/svn/map:refs/notes/commits

Run git fetch after adding that line to the configuration to obtain the notes; after that git log will show the revisions numbers in its output.

Another approach is to embed the revision number (along with other information, if needed) right into the commit message. SVN Mirror add-on has the svn.gitCommitMessage that allows setting a Git commit message template and include different information from SVN revision in the commit message. This setting should be added right to the mapping configuration:

[svn]
    trunk = …
    branches = …
    tags = …
    …
    svn.gitCommitMessage = PATTERN

The setting supports several placeholders, so if it’s set like this:

gitCommitMessage = SVN %revision@%branch\\n%message

then the Git commit message will look like this:

  $ git log -v
  commit d5c7c9e2518a5e8942c26d7cda5ace61ddb7c045
  Author: John Dow <johndoe@example.com>
  Date:   Thu Jun 29 08:38:02 2017 +0000

      SVN 197@trunk
      gitCommitMessage example

Since the information is embedded in the commit message, it will be visible everywhere, while Git notes require special handling to be seen. On the other hand, this approach changes original revision message that might not be desired.

I don’t see where to add that “fetch” line in Bitbucket. I tried putting it into the branch mapping but got an error and no revision info.
The “gitCommitMessage” line worked though. Are there more things other than revision and branch that can be added?
Thanks.

Hi Tom,

this line is not to be added in Bitbucket, it should be added to Git configuration file in a working copy of the repository:

  • clone the Bitbucket repository with git clone command (or with a GUI Git client you prefer)
  • open the working copy Git configuration file (.git/config in the working copy directory) and add the ‘fetch’ line to the ‘origin’ section.
  • run git fetch in the working copy

After that git log command will show revisions number in the output.

Yes, there are some other placeholders, here are the details:

https://subgit.com/documentation/config-options.html#svn.gitCommitMessage

Hi Ildar Khusainov ,

regarding 2nd approach, the “svn.gitCommitMessage”, if I add this setting into our mapping configuration and commit message will be overridden by our message with the rev? or it will append to the svn commit msg ?

can you please confirm

Thanks & Regards,
Manju NS

Hi Manju NS,

it depends on how you configure it. There is the %message placeholder that allows keeping original SVN revision message. So if you add that placeholder in the svn.gitCommitMessage pattern, the original message won’t be overridden, but will be extended by some additional information according to the svn.gitCommitMessage setting (revision number, for example). If that %message placeholder if omitted in the setting, then the original message won’t be present in the Git commit message thus being effectively overridden.

Hi Ildar Khusainov,

i don’t want to override the original commit message

for example, below is the output of the git log which is mirrored from svn if we add the below branch map settings what will be the out of the git log ?(eg: svn rev is 1234 and branch:trunk)

$ git log -v filename.c
ESC[33mcommit 49be74d2d48838dde9ed373237249a1d496b6351ESC[m
Author:
Date: Mon Oct 12 12:09:49 2020 +0000

BUG-84266

Enable main options feature bit by default

Submitted by:       
Reviewed by:        
Differential Revision:      

Branch map settings: ```
gitCommitMessage = SVN %revision@%branch\n%message

Hi Manju NS,

with this message and gitCommitMessage pattern the resulting message should look like this:

SVN 1234@trunk
BUG-84266

Enable main options feature bit by default

Submitted by:       
Reviewed by:        
Differential Revision:

Great, Thanks a lot

You are very welcome!

Note, that the gitCommitMessage pattern is being applied during the actual translation, it cannot be applied to already translated commits. So if the initial import has already been done by the moment the setting applied, then it will only affect new revisions.

thanks, good Note