Projects/MoveToGit/UsingSvn2Git: Difference between revisions

    From KDE TechBase
    (→‎Testing a module: fix the header to better match the content)
    (→‎Step-by-Step on writing rules for a module: rewrite this section to be easier readable.)
    Line 74: Line 74:
    === Step-by-Step on writing rules for a module ===
    === Step-by-Step on writing rules for a module ===


    * Check wether there are already rules for this module in the kde-ruleset repository. If there are no rules yet create a new rules file and add the create repository part.
    ==== Analyzing Subversion history to write rules ====
    * Execute svn log -v --stop-on-copy file:///path/to/kde_svn/trunk/KDE/module. This will give you a history of the given module in trunk, it'll stop on the first commit that copied the code from somewhere else. The verbose output will allow you to see where this copy came from.
    First of all you should check wether there are already rules for this module in the kde-ruleset repository. If there are rules already please go down to "Running svn2git"
    * Write a rule for the path /trunk/KDE/module that puts all commits into the repository for module under the branch "master":
     
    If there are no rules yet, lets start with the master (aka trunk) branch. The easiest way to find out history with svn is executing:
    <pre>svn log -v --stop-on-copy file:///path/to/kde_svn/trunk/KDE/module</pre>
     
    This will give you a history of the given module in trunk, it'll stop on the first commit that copied the code from somewhere else. The verbose output will allow you to see where this copy came from.
     
    Now we have a starting point to write a rule, we want all commits from this path in our module repository in the master branch:
    <pre>
    <pre>
    match /trunk/KDE/module/
    match /trunk/KDE/module/
    Line 83: Line 89:
    end match
    end match
    </pre>
    </pre>
    * If the module was copied from somewhere you'll see a "from: /some/other/path:<revision>" in the commit log. We can use that to follow the history back to that place with svn log -v --stop-on-copy file:///path/to/kde_svn/some/other/path@revision. The @revision is important as the original path usually doesn't exist anymore.
    If the log stops at a commit that copied the module from somewhere, we need to
    * Write another rule for /some/other/path taking all commits into the master branch
    follow this to also get the history imported from the "old" place the module resided. The same svn command can be used with slightly different path argument:
    * rinse and repeat until you've found the first commit that initially added the module
     
    * Next step are the branches, those are usually in /branches/KDE/x.y/module. It works the same way as with the master branch, just the resulting rule is slightly different:
    <pre>svn log -v --stop-on-copy file:///path/to/kde_svn/some/other/path@revision</pre>
    The @revision is important as the original path usually doesn't exist anymore. With this we can write the next rule to the rules file and repeat until we've finally reached the point where the code was initially imported into svn (or probably cvs in the old days)
     
    Now we can take care of the branches, this is a bit more involved as there may be multiple branches scattered over the /branches directory in svn. You can use the same commands as before to find out the history of a branch if you know the path. This time however you can stop following the source of copy-operations once you've found a source that you've already matched in a rule. That way your branch will be connected to the branch it originated from (which is often trunk aka master) in git.
     
    A useful help with finding branches is svn ls in combination with the path@revision syntax, that way you can view the content of a particular svn directory as it was in an older revision. With this you can even find branches that are not visible (have been deleted) in the current revision.
     
    The rule for putting commits into a git branch in the final repository is only slightly different (the example is for a core module):
    <pre>
    <pre>
    match /branches/KDE/4.4/module
    match /branches/KDE/4.4/module
    Line 93: Line 106:
    end match
    end match
    </pre>
    </pre>
    This time you only need to follow the branch to the point where it was copied from trunk/. There might be additional work-branches scattered over the /branches/ subversion directory.
     
    * Last but not least the tags, usually to be found in tags/KDE/x.y.z/module.
    And last are the tags, this works the same as branches and trunk, except for using branch refs/tags/v<tag-version> for the branch parameter.
    * Now run the svn2git tool with your rules file:
     
    ==== Running svn2git ====
    This is the easiest, but most time-consuming part. As example lets say that in our current working directory we have the kde rules repository in kde-ruleset subdir, the svn2git tool in the svn2git subdir and the KDE repository in the kde_svn subdir:
    <pre>
    svn2git/svn-all-fast-export --identity-map kde-ruleset/account-map --rules kde-ruleset/module kde_svn
    </pre>
     
    This will take a few hours usually, but it'll spit out the progress. The tool also writes a logfile to module.log, so in case something goes wrong you can find more details in there.
     
    Once its done you should have a new "module" git repository in your current working directory.
     
    ==== Checking for proper history in the new git repository ====
    A very easy way to check wether the history was imported properly is to use the gitk tool from git. It shows you a graphical representation of the history in the git repository which makes it easy to identify where something is wrong.
     
    The tool should be run with the --all switch so it shows all branches.
     
    You can now scroll through the history to check wether things have been imported correctly.
     
    First and foremost there should be the master branch starting at the top with the most recent commit to trunk/ and ending in the oldest commit that imported the code into KDE's svn or cvs repository.  
     
    From the master branch there should be several branches going away for each branch you imported. And eventually also branches that start from another non-master branch.
     
    Things that you should look out for are branches that start "nowhere", that is the first commit in the branch has no parent in another branch or master. This means that svn2git didn't see a commit that created this branch from another using a svn cp command. That can mean that you may have forgotton to add a match rule for some path or that the same path was used for different branches in different revisions. The same applies to tags which have a commit without any parent.
     
    This can usually be fixed by using svn log and svn ls to follow the history of the branch. Eventually you might need to apply the min/max revision paramters.
     
    You'll notice that some tags are looking like this:
     
    <pre>
    <pre>
    svn-all-fast-export --identity-map kde-ruleset/account-map --rules yourrulesfile kde_svn
    |
    * * <v1.2.3>
    | |
    * *
    | /
    *
    </pre>
    </pre>
    Where kde_svn is the svn database on your disk. This will take a while.
     
    * Once its done you should have a new "module" git repository in your current working directory. Now to check wether its sane (you might have to install gitk as some distro's split it out of the git core package):
    Thats normal for our tags even if a bit ugly. The reason is that often compile-fixes are done in trunk/ after the tag has been created and then the commit has been merged over to the tag.
     
    Another thing however are tags that are named vx.y.z_124321. These are tags that have been deleted and re-created later. You can usually see that in the svn log history, these tags can either be manually deleted after the repository creation using git tag or you can add rules that ignore certain revisions of the tag-path before the one putting the commits into the git repository:
     
    <pre>
    <pre>
    gitk --all
    match /tags/KDE/3.3.2/kdelibs
      min revision 424234
      max revision 424236
    end match
    match /tags/KDE/3.3.2/kdelibs
      repository kdelibs
      branch refs/tags/3.3.2
    end match
    </pre>
    </pre>
    This gives you a nice graphical view on the history of the module that you just imported.


    You can now scroll through the history to check wether things have been imported correctly. Things to look out for are:
    If you choose to delete them manually please make sure to document this with a textfile or inside the rule file so if someone else does the conversion later again he'll know what manual steps you did.
    ** Branches that start nowhere. That is the oldest commit of the branch has no parent commit associated. This means that svn2git wasn't able to find out where this branch was created from. Usual causes are a missing match rule for the path where the branch originated from or some mismatching rules or the need for recurse action.
     
    ** Tags that belong to a commit with no parent, again this means that a rule might be missing or that the recurse action is needed. This happens quite a bit for the really old tags
    ==== Getting Help ====
    ** Tags that are atttached to a "branch", this happens if the directory for the tag (i.e. /tags/KDE/4.4.0/kdelibs) has not only the copy-commit, but also additional commits on top of it. This happens quite often for the core module when compile errors are found after the tagging. Its not very nice, but unfortunately not fixable.
    If you run into strange things or can't find a rule for something you can reach the KDE Git migration team on IRC: irc.freenode.org, #kde-git or on the <a href="https://mail.kde.org/mailman/listinfo/kde-scm-interest">kde-scm-interest mailinglist</a>
    ** Other than the above special cases the history should be complete, i.e. the master branch should start at the top with the most-recent commit and end at the bottom with the oldest commit. All other branches should either start from the master branch directly or indirectly from another branch.
    * If you find any problems and can't see a way to fix them easily, join the kde-git team on irc.freenode.org in the #kde-git channel or send a mail to the kde-scm-interest mailinglist.

    Revision as of 21:47, 2 March 2010

    This page documents how to go about getting a KDE module ready for the Great Git Migration of 2010.

    Getting the tools

    The necessary tools are hosted at http://www.gitorious.org/svn2git. To get started do:

    git clone git://gitorious.org/svn2git/svn2git.git git clone git://gitorious.org/svn2git/kde-ruleset.git

    This will get you the source code to build svn2git and the KDE ruleset files as they currently exist. Build the svn2git tool before moving on to the next step.

    Building svn2git

    Make sure you have Qt4 installed, then simply issue qmake && make to build the executable called "svn-all-fast-export"

    How rulesets work

    The format for the svn2git rules is pretty simple. First and foremost you have to declare some repositories:

    create repository kdelibs
    end repository
    

    This tells svn2git that it should create a git repository called "kdelibs" that we can later on use to put commits into it.

    The rest of the file are rules matching specific paths in Subversion, each rule specifies what to do with the commits that appeared at the given path. The possible actions are ignoring them or adding them to a particular branch in a particular repository. Note: Ignoring is done by simply leaving out the information about the repository and the branch.

    As examples are more explanatory, the following rule would put all commits from 123453 to 456789 from the path /trunk/KDE/kdelibs into the master branch of the kdelibs repository:

    match /trunk/KDE/kdelibs/
      min revision 123453
      max revision 456789
      repository kdelibs
      branch master
    end match
    

    The min and max revision are useful in cases where the same path in SVN contains code for different branches. An example would be KDevelop3, where KDevelop 3.3 was shipped with KDE 3.5 until 3.5.7, 3.5.8 contained KDevelop 3.4 and 3.5.9 contained KDevelop 3.5 and all of those kdevelop versions are now under /branches/KDE/3.5/kdevelop.

    The two revision parameters are however not mandatory, if they're left out, then all commits that went to the given matching path in SVN are taken over into the specified branch.

    To generate tags with git you use a special format for the branch parameter: refs/tag/<tagname>. So to put all commits from /tags/KDE/4.4.0/kdelibs into the v4.4.0 tag in the kdelibs git repository the rule would be like this:

    match /tags/KDE/4.4.0/kdelibs/
      repository kdelibs
      branch refs/tags/v4.4.0
    end match
    

    For more examples see the svn2git/samples/ directory and the rules in the kde-ruleset repository.

    TODO: Add some information how the recurse-stuff works.

    Important Details

    • All matching rules need to end with a '/', else the tool will crash at some point. This is a known bug. The only exception are the rules using the recurse-action.
    • The rules form an ordered list that the tool goes through while matching the changed paths for each commit. So if two rules match the same path and neither of the two has more matching criteria, then the rule that is written further up in the file wins. This is useful to exclude certain commits from the extraction process, if you look at the existing kde ruleset you'll notice that at the top some revisions are ignored.

    Setting up your system

    You will need ~60GB (is that correct?) of disk space to get started, as the process requires a copy of the KDE svn database. There is a script that will download this for you (and which can be used to update it periodically using rsync) in kde-ruleset/bin/startSync. By default the startSync script runs rsync in "dry run" mode, so before using it to actually get the svn database edit the startSync script and remove the -n from both rsync lines.

    more stuff goes here ...

    Step-by-Step on writing rules for a module

    Analyzing Subversion history to write rules

    First of all you should check wether there are already rules for this module in the kde-ruleset repository. If there are rules already please go down to "Running svn2git"

    If there are no rules yet, lets start with the master (aka trunk) branch. The easiest way to find out history with svn is executing:

    svn log -v --stop-on-copy file:///path/to/kde_svn/trunk/KDE/module

    This will give you a history of the given module in trunk, it'll stop on the first commit that copied the code from somewhere else. The verbose output will allow you to see where this copy came from.

    Now we have a starting point to write a rule, we want all commits from this path in our module repository in the master branch:

    match /trunk/KDE/module/
      repository module
      branch master
    end match
    

    If the log stops at a commit that copied the module from somewhere, we need to follow this to also get the history imported from the "old" place the module resided. The same svn command can be used with slightly different path argument:

    svn log -v --stop-on-copy file:///path/to/kde_svn/some/other/path@revision

    The @revision is important as the original path usually doesn't exist anymore. With this we can write the next rule to the rules file and repeat until we've finally reached the point where the code was initially imported into svn (or probably cvs in the old days)

    Now we can take care of the branches, this is a bit more involved as there may be multiple branches scattered over the /branches directory in svn. You can use the same commands as before to find out the history of a branch if you know the path. This time however you can stop following the source of copy-operations once you've found a source that you've already matched in a rule. That way your branch will be connected to the branch it originated from (which is often trunk aka master) in git.

    A useful help with finding branches is svn ls in combination with the path@revision syntax, that way you can view the content of a particular svn directory as it was in an older revision. With this you can even find branches that are not visible (have been deleted) in the current revision.

    The rule for putting commits into a git branch in the final repository is only slightly different (the example is for a core module):

    match /branches/KDE/4.4/module
      repository module
      branch 4.4
    end match
    

    And last are the tags, this works the same as branches and trunk, except for using branch refs/tags/v<tag-version> for the branch parameter.

    Running svn2git

    This is the easiest, but most time-consuming part. As example lets say that in our current working directory we have the kde rules repository in kde-ruleset subdir, the svn2git tool in the svn2git subdir and the KDE repository in the kde_svn subdir:

    svn2git/svn-all-fast-export --identity-map kde-ruleset/account-map --rules kde-ruleset/module kde_svn
    

    This will take a few hours usually, but it'll spit out the progress. The tool also writes a logfile to module.log, so in case something goes wrong you can find more details in there.

    Once its done you should have a new "module" git repository in your current working directory.

    Checking for proper history in the new git repository

    A very easy way to check wether the history was imported properly is to use the gitk tool from git. It shows you a graphical representation of the history in the git repository which makes it easy to identify where something is wrong.

    The tool should be run with the --all switch so it shows all branches.

    You can now scroll through the history to check wether things have been imported correctly.

    First and foremost there should be the master branch starting at the top with the most recent commit to trunk/ and ending in the oldest commit that imported the code into KDE's svn or cvs repository.

    From the master branch there should be several branches going away for each branch you imported. And eventually also branches that start from another non-master branch.

    Things that you should look out for are branches that start "nowhere", that is the first commit in the branch has no parent in another branch or master. This means that svn2git didn't see a commit that created this branch from another using a svn cp command. That can mean that you may have forgotton to add a match rule for some path or that the same path was used for different branches in different revisions. The same applies to tags which have a commit without any parent.

    This can usually be fixed by using svn log and svn ls to follow the history of the branch. Eventually you might need to apply the min/max revision paramters.

    You'll notice that some tags are looking like this:

    |
    * * <v1.2.3>
    | |
    * *
    | /
    *
    

    Thats normal for our tags even if a bit ugly. The reason is that often compile-fixes are done in trunk/ after the tag has been created and then the commit has been merged over to the tag.

    Another thing however are tags that are named vx.y.z_124321. These are tags that have been deleted and re-created later. You can usually see that in the svn log history, these tags can either be manually deleted after the repository creation using git tag or you can add rules that ignore certain revisions of the tag-path before the one putting the commits into the git repository:

    match /tags/KDE/3.3.2/kdelibs
      min revision 424234
      max revision 424236
    end match
    match /tags/KDE/3.3.2/kdelibs
      repository kdelibs
      branch refs/tags/3.3.2
    end match
    

    If you choose to delete them manually please make sure to document this with a textfile or inside the rule file so if someone else does the conversion later again he'll know what manual steps you did.

    Getting Help

    If you run into strange things or can't find a rule for something you can reach the KDE Git migration team on IRC: irc.freenode.org, #kde-git or on the <a href="https://mail.kde.org/mailman/listinfo/kde-scm-interest">kde-scm-interest mailinglist</a>