Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: The E on May 23, 2015, 03:51:49 am

Title: Bringing over large svn patches to our git repo
Post by: The E on May 23, 2015, 03:51:49 am
Yesterday, Karajorma had a bit of a problem. His work on sexp container classes (http://www.hard-light.net/forums/index.php?topic=88613.0) was locked up in a patch file against the last revision of our SVN, and none of the solutions we found for converting an svn patch into a git patch actually worked (If you know how to do this, please mention it!).

I then volunteered to convert the stuff to git manually. Kara then asked me to document the process I used so that others may learn from it.

So, basically, here's the workflow I used.

And that's it.
Title: Re: Bringing over large svn patches to our git repo
Post by: Goober5000 on May 23, 2015, 04:04:04 pm
Good post. You may want to merge it into the master sticky thread (http://www.hard-light.net/forums/index.php?topic=82688.0).

(Incidentally, the master sticky should also be updated with git instructions at some point.)
Title: Re: Bringing over large svn patches to our git repo
Post by: niffiwan on May 23, 2015, 05:59:50 pm
Er, neatly highlighting one issue of documentation on the forum, only the original poster (or an admin) can update a post.  I much prefer the wiki for this sort of doco, as anyone sufficiently motivated can make the updates (you can see that almost every reference to SVN on the wiki has already been updated :D)

</soapbox>
Title: Re: Bringing over large svn patches to our git repo
Post by: Goober5000 on May 23, 2015, 08:02:58 pm
But The E, being a mod of the SCP forum, has the ability to edit posts -- n'est-ce pas?
Title: Re: Bringing over large svn patches to our git repo
Post by: niffiwan on May 23, 2015, 08:46:01 pm
True; but OP+Admins+Mods is still less than "all Wiki accounts"!
Title: Re: Bringing over large svn patches to our git repo
Post by: Jackho on May 24, 2015, 02:37:32 am
Hi,
You might find this useful (or not):

Converting a Subversion repository to Git (http://john.albin.net/git/convert-subversion-to-git)
Converting SVN Commits to Git Patches (https://jbowes.wordpress.com/2009/06/23/converting-svn-commits-to-git-patches/)

Just my 2 cents
Title: Re: Bringing over large svn patches to our git repo
Post by: chief1983 on May 24, 2015, 11:00:51 am
I'm still not sure why manually copying the files should have been necessary as opposed to just applying the patch directly to the git repo at the corresponding git hash that matches the svn revision.  The GNU patch utility should handle it, barring maybe some whitespace corrections.
Title: Re: Bringing over large svn patches to our git repo
Post by: The E on May 24, 2015, 11:06:49 am
TRied that, didn't work. I mean, it could just be me not knowing all the right commandline incantations for patch, and I am very definitely interested in a less janky way to do this.
Title: Re: Bringing over large svn patches to our git repo
Post by: niffiwan on May 24, 2015, 04:23:21 pm
I gave it a quick attempt, "git apply --verbose" couldn't find where to apply a heap of chunks, GNU/Linux "patch --binary" managed to apply everything except the MSVC project changes.  I'm guessing there's some whitespace / line ending errors in the patch somewhere, but I didn't continue to look because I've previously found errors in the MSVC project files practically impossible to resolve without serious hacking of the diff.  Or applying by hand, in either case the method outlined above is an easier way to do it.
Title: Re: Bringing over large svn patches to our git repo
Post by: Bobboau on May 27, 2015, 05:17:40 pm
do you still have your svn repos around? could you apply the patch to svn, to get the full file, then just copy/paste the file into the git repo of the same version as the oldest svn and commit?
Title: Re: Bringing over large svn patches to our git repo
Post by: AdmiralRalwood on May 27, 2015, 06:37:16 pm
do you still have your svn repos around? could you apply the patch to svn, to get the full file, then just copy/paste the file into the git repo of the same version as the oldest svn and commit?
Might want to re-read the first post (http://www.hard-light.net/forums/index.php?topic=89778.msg1786280#msg1786280)...
Title: Re: Bringing over large svn patches to our git repo
Post by: Zacam on June 09, 2015, 01:32:48 am
My process was (and this was a long while ago):

Got a .diff file. Manually made the changes to SVN to generate a .patch file. Compared the two in order to note the differences as a template, used that format to inter-convert either/or to the other.

I could probably whip up a small something that could manage conversion, but are there really that many outstanding SVN .patch files that this would be needed for?

I'm also more than happy to volunteer converting one to the other (in either direction).
Title: Re: Bringing over large svn patches to our git repo
Post by: jr2 on June 18, 2015, 03:20:21 am
@Zacam if you do make something, not sure if this is any help, but here:

Quote from: https://jbowes.wordpress.com/2009/06/23/converting-svn-commits-to-git-patches/

Code: [Select]
#!/usr/bin/python
#
# svnrev2git.py - Convert an SVN revsion to a Git patch.
#
# Author: James Bowes <[email protected]>
#
# Usage:
#   $> cd my-svn-repo
#   $> python svnrev2git.py [AUTHORS_FILE] [REV_RANGE | REVSION [REVISION..]]
#
#   AUTHORS_FILE - a CSV of  svn username, full name, email
#   REV_RANGE - an svn revision range, like 100-700
#   REVISION - a single svn revision
#
#   You may specify either a revision range, or a series of individual
#   svn revisions
#
# Output:
#   A series of git style patch files, one per svn revision, which can then be
#   applied with 'git am'
#
# Why use this instead of 'git svn'?
#   I had done a large repo conversion via git svn where we wanted no downtime
#   for the switchover. After removing the git svn specific info from our git
#   commits, I used this tool to bring in commits from svn, keeping svn and git
#   in sync, until we were ready to switch.

import sys
import commands

def svnlog_to_gitlog(authors, svnlog):

    lines = svnlog.split("\n  lines = lines[1:-1]

    metainfo = lines[0].split(" | ")
    subject = lines[2]
    description = lines[3:]

    author = metainfo[1]

    day = metainfo[2].split("(")[1][:-1]
    time = metainfo[2].split(" ")[1]
    offset = metainfo[2].split(" ")[2]

    gitlog = []
    gitlog += ["From: %s <%s>" % authors[author]]
    gitlog += ["Date: %s %s %s" % (day, time, offset)]
    gitlog += ["Subject: [PATCH] %s" % subject]
    gitlog += [""]
    gitlog += description
    gitlog += [""]

    return '\n'.join(gitlog)

def svndiff_to_gitdiff(svndiff):
    lines = svndiff.split("\n   gitdiff = []
    for line in lines:
        if line.startswith("--- "):
            gitdiff.append("--- a/" + line[4:])
        elif line.startswith("+++ "):
            gitdiff.append("+++ b/" + line[4:])
        else:
            gitdiff.append(line)

    return '\n'.join(gitdiff)

def make_patch(authors, rev):
    out = commands.getoutput("svn log -c %s ." % rev)

    if len(out.split("\n 2:
        print "skipping r%s" % rev
        return

    patch = open(rev + ".patch", 'w')
    patch.write(svnlog_to_gitlog(authors, out))
    patch.write("---\n\n   out = commands.getoutput("svn diff -c %s ." % rev)
    patch.write(svndiff_to_gitdiff(out))

    patch.write("\n---\n  patch.write("svnrev2git.py\n   patch.close()
    print "wrote %s.patch" % rev

def main(args):
    author_file = open(args[0])
    authors = {}

    print "loading authors"
    for line in author_file.readlines():
        parts = line.strip().split(", ")
        authors[parts[0]] = (parts[1], parts[2])

    author_file.close()

    revs = args[1:]

    if len(revs) == 1 and '-' in revs[0]:
        start, end = revs[0].split('-')
        start = int(start)
        end = int(end)
        revs = [str(x) for x in range(start, end + 1)]

    for rev in revs:
        make_patch(authors, rev)

if __name__ == "__main__":
    main(sys.argv[1:])

Quote from: https://gist.github.com/neosergio/5979125
Code: [Select]
git diff  --no-prefix --ignore-space-at-eol | sed -e "s/^diff --git [^[:space:]]*/Index:/" -e "s/^index.*/===================================================================/" > changes.patch


If this isn't useful, my apologies.