~ubuntu-branches/ubuntu/natty/bzr-fastimport/natty

« back to all changes in this revision

Viewing changes to exporters/darcs/x2d

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-09-26 00:21:27 UTC
  • mfrom: (1.1.3 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090926002127-naki02grwmkapav6
Tags: 0.9.0~bzr243-1
* New upstream snapshot.
* Bump standards version to 3.8.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#   x2d - convert git, bzr or hg repos to darcs using fast-export
 
4
#
 
5
#   Copyright (c) 2008 by Miklos Vajna <vmiklos@frugalware.org>
 
6
#
 
7
#   This program is free software; you can redistribute it and/or modify
 
8
#   it under the terms of the GNU General Public License as published by
 
9
#   the Free Software Foundation; either version 2 of the License, or
 
10
#   (at your option) any later version.
 
11
#
 
12
#   This program is distributed in the hope that it will be useful,
 
13
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#   GNU General Public License for more details.
 
16
#
 
17
#   You should have received a copy of the GNU General Public License
 
18
#   along with this program; if not, write to the Free Software
 
19
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
20
#   USA.
 
21
#
 
22
 
 
23
usage()
 
24
{
 
25
        echo "Usage: x2d -f format repo"
 
26
}
 
27
 
 
28
die()
 
29
{
 
30
        echo "$@"
 
31
        usage
 
32
        exit 1
 
33
}
 
34
 
 
35
check_up_to_date()
 
36
{
 
37
        upstreamnum=$(darcs show repo|grep 'Num Patches'|sed 's/.*: //')
 
38
        if [ "$upstreamnum" = "$(cd $origin; eval $*)" ]; then
 
39
                echo "No remote changes to pull!"
 
40
                exit 0
 
41
        fi
 
42
}
 
43
 
 
44
case $1 in
 
45
        -h|--help)
 
46
                usage
 
47
                exit 0
 
48
                ;;
 
49
        -f)
 
50
                format="$2"
 
51
                shift 2
 
52
                ;;
 
53
esac
 
54
 
 
55
[ -n "$format" ] || die "Source format is not given!"
 
56
 
 
57
case $format in
 
58
        git|bzr|hg)
 
59
                ;;
 
60
        *)
 
61
                die "The requested source format is not yet supported!"
 
62
                ;;
 
63
esac
 
64
 
 
65
origin="$1"
 
66
shift 1
 
67
 
 
68
[ -d "$origin" ] || die "Source repo does not exist!"
 
69
 
 
70
# convert to abspath
 
71
cd $origin
 
72
origin=$(pwd)
 
73
 
 
74
dmark="$origin.darcs/_darcs/fast-import/dfe-marks"
 
75
fmark="$origin.darcs/_darcs/fast-import/ffi-marks"
 
76
 
 
77
mkdir -p $origin.darcs
 
78
cd $origin.darcs
 
79
 
 
80
common_opts="--logfile $origin.darcs/_darcs/fast-import/log"
 
81
pypath="/$(python -c 'from distutils import sysconfig; print sysconfig.get_python_lib()[1:]')/"
 
82
 
 
83
if [ ! -f $dmark ]; then
 
84
        darcs init
 
85
        mkdir -p _darcs/fast-import
 
86
        case $format in
 
87
                git)
 
88
                        (cd $origin; git fast-export --export-marks=$fmark HEAD) | \
 
89
                                darcs-fast-import --export-marks=$dmark $common_opts
 
90
                        ;;
 
91
                bzr)
 
92
                        (cd $origin; bzr fast-export \
 
93
                                --export-marks=$fmark . ) | darcs-fast-import --export-marks=$dmark $common_opts
 
94
                        ;;
 
95
                hg)
 
96
                        (cd $origin; $pypath/bzrlib/plugins/fastimport/exporters/hg-fast-export.py -r . ) | \
 
97
                                darcs-fast-import --export-marks=$dmark $common_opts
 
98
        esac
 
99
else
 
100
        case $format in
 
101
                git)
 
102
                        check_up_to_date "git rev-list HEAD |wc -l"
 
103
                        (cd $origin; git fast-export --export-marks=$fmark --import-marks=$fmark HEAD) | \
 
104
                                darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts
 
105
                        ;;
 
106
                bzr)
 
107
                        # bzr revno is not good here, because at merges
 
108
                        # it produces less revision than the number we
 
109
                        # have in darcs
 
110
                        check_up_to_date "bzr log --include-merges |grep -c revno:"
 
111
                        (cd $origin; bzr fast-export \
 
112
                                --export-marks=$fmark --import-marks=$fmark . ) | \
 
113
                                darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts
 
114
                        ;;
 
115
                hg)
 
116
                        check_up_to_date 'echo $(($(hg tip --template "{rev}")+1))'
 
117
                        (cd $origin; $pypath/bzrlib/plugins/fastimport/exporters/hg-fast-export.py -r . ) | \
 
118
                                darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts
 
119
                        ;;
 
120
        esac
 
121
fi