summaryrefslogtreecommitdiff
path: root/exporters/darcs/d2x
blob: 85e15e206d49449ff59e29585cb6252fc0f9b1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
#
#   d2x - convert darcs repos to git, bzr or hg using fast-import
#
#   Copyright (c) 2008 by Miklos Vajna <vmiklos@frugalware.org>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

usage()
{
	echo "Usage: d2x -f format darcsrepo"
}

die()
{
	echo "$@"
	usage
	exit 1
}

check_up_to_date()
{
	upstreamnum=$(cd $origin; darcs show repo|grep 'Num Patches'|sed 's/.*: //')
	if [ "$upstreamnum" = "$(eval $*)" ]; then
		echo "No remote changes to pull!"
		exit 0
	fi
}

case $1 in
	-h|--help)
		usage
		exit 0
		;;
	-f)
		format="$2"
		shift 2
		;;
esac

[ -n "$format" ] || die "Target format is not given!"

case $format in
	git|bzr|hg)
		;;
	*)
		die "The requested target format is not yet supported!"
		;;
esac

origin="$1"
shift 1

[ -d "$origin" ] || die "Source repo does not exist!"

# convert to abspath
cd $origin
origin=$(pwd)

dmark="$origin.$format/darcs/dfe-marks"
fmark="$origin.$format/darcs/ffi-marks"

mkdir -p $origin.$format/darcs
cd $origin.$format

common_opts="--working $origin.$format/darcs/repo --logfile $origin.$format/darcs/log $origin"
if [ ! -f $dmark ]; then
	case $format in
		git)
			git --bare init
			darcs-fast-export $* --export-marks=$dmark $common_opts | \
				git fast-import --export-marks=$fmark
			;;
		bzr)
			bzr init-repo .
			darcs-fast-export $* --export-marks=$dmark $common_opts | \
				bzr fast-import --export-marks=$fmark -
			;;
		hg)
			hg init
			darcs-fast-export $* $origin | \
				hg fastimport -
	esac
else
	case $format in
		git)
			check_up_to_date "git rev-list HEAD |wc -l"
			darcs-fast-export $* --export-marks=$dmark --import-marks=$dmark $common_opts | \
				git fast-import --export-marks=$fmark --import-marks=$fmark
			;;
		bzr)
			check_up_to_date "cd master; bzr revno"
			darcs-fast-export $* --export-marks=$dmark --import-marks=$dmark $common_opts | \
				bzr fast-import --export-marks=$fmark --import-marks=$fmark -
			;;
		hg)
			die "Incremental conversion to hg is not yet supported by hg fastimport."
			;;
	esac
fi