View Single Post
Old 05-30-2013, 03:54 AM   #1
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,299
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Switching to git

Hi all,

Just a heads up. I am switching calibre's source control system to git from bzr. The primary motivation for the move was that bzr was becoming too inefficient at calibre's size. The version history takes ~650MB in bzr and only ~130MB in git. This means that for a new developer the time taken to get calibre's code decreases to a quarter of the current time. For instance, on my internet connection, getting a fresh checkout of calibre's code has gone from ~1 hour to ~10 minutes.

Also, bzr development appears to be dead, see http://stationary-traveller.eu/pages...ospective.html. While that does not matter for bzr itself, it does mean that the support tools and ecosystem will stagnate/decline over time.

Updated instructions for getting the source code are in the manual.

The git repository is hosted on GitHub at https://github.com/kovidgoyal/calibre

Apologies for the inconvenience, however, I felt that this move was best for calibre's future. I did poll the top 5 recent calibre committers, of whom 2 were for it, 2 against and 1 neutral.

If you have any questions or concerns, do let me know and while I'm not a git expert, I will try to help

Below is a basic guide to setting up your own fork of calibre in a way that will allow you to submit pull requests for inclusion into my repository:
Spoiler:

1) Setup git on your machine as described in this article: https://help.github.com/articles/set-up-git

2) Setup ssh keys for authentication to GitHub, as described here: https://help.github.com/articles/generating-ssh-keys

3) Go to https://github.com/kovidgoyal/calibre and click the Fork button.

4) In a Terminal do
Code:
git clone git@github.com:<username>/calibre.git
Replace <username> above with your github username. That will get your fork checked out locally.

5) You can make changes and commit them whenever you like. When you
are ready to have me merge your work, do a
Code:
git push
and go to https://github.com/<username>/calibre and click the Pull Request to generate a pull request that I can merge.

6) You can update your local copy with code from my repo at any time by doing:
Code:
git pull upstream


Just in case, like me, you loved the bzr qdiff tool to view diffs, I've created a small wrapper script that allows you to use it with git:
Spoiler:

Code:
#!/usr/bin/env python
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'

import sys
import subprocess
import os
import shutil
import atexit
import tempfile


def ipython(ns={}):
    import IPython
    IPython.embed(user_ns=ns)


def walk(d):
    for record in os.walk(d):
        for f in record[-1]:
            f = os.path.join(record[0], f)
            if os.path.islink(f):
                src = os.path.realpath(f)
                os.unlink(f)
                shutil.copy2(src, f)
            yield os.path.relpath(f, d)


def do_diff(left, right):
    rfiles = frozenset(walk(type('')(right)))
    os.chdir(left)
    files = frozenset(walk('.'))
    if not files and not rfiles:
        raise SystemExit(0)

    # Create and populate bzr repo
    subprocess.check_call(['bzr', 'init', '-q'])
    subprocess.check_call(['bzr', 'add', '-q'] + list(files))
    subprocess.check_call(['bzr', 'commit', '-m', 'left', '-q'])

    # Update files in left from right
    for f in files | rfiles:
        src = os.path.realpath(os.path.join(right, f))
        if os.path.exists(src):
            base = os.path.dirname(f)
            if base and not os.path.exists(base):
                os.makedirs(base)
            shutil.copy2(src, f)
        else:  # File was deleted
            os.unlink(f)

    newf = rfiles - files
    if newf:
        subprocess.check_call(['bzr', 'add', '-q'] + list(newf))

    raise SystemExit(subprocess.Popen(['bzr', 'qdiff']).wait())

left, right = sys.argv[1:3]
# ipython(locals())

if not os.path.isdir(left):
    # Single file diff, we make the directory structure ourselves
    left = tempfile.mkdtemp(prefix='difftool_left_')
    right = tempfile.mkdtemp(prefix='difftool_right_')
    atexit.register(shutil.rmtree, left)
    atexit.register(shutil.rmtree, right)
    path = sys.argv[-1]
    base = os.path.dirname(path)
    if base:
        for x in (left, right):
            os.makedirs(os.path.join(x, base))
    shutil.copy2(sys.argv[1], os.path.join(left, path))
    shutil.copy2(sys.argv[2], os.path.join(right, path))

do_diff(left, right)
Save this script somewhere on your path and make it executable (on windows you'd probably have to create a .bat file that calls python with this script). Then in your git config file add the following

Code:
[diff]
    tool = bzr
[difftool]
    prompt = false
[difftool "bzr"]
    cmd = /path/to/the/executable/script $LOCAL $REMOTE $MERGED
You can then use it with:
Code:
git difftool -d

Last edited by kovidgoyal; 05-30-2013 at 11:07 PM.
kovidgoyal is online now   Reply With Quote