fix timezones in darcs-fast-export, take 2
[girocco-darcs-fast-export.git] / d2x
blob959cc009453d152b3af7cbec007311eec430c344
1 #!/bin/sh
3 # d2x - convert darcs repos to git, bzr or hg using fast-import
5 # Copyright (c) 2008 by Miklos Vajna <vmiklos@frugalware.org>
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.
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.
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.
23 usage()
25 echo "Usage: d2x -f format darcsrepo"
28 die()
30 echo "$@"
31 usage
32 exit 1
35 check_up_to_date()
37 upstreamnum=$(cd $origin; darcs show repo|grep 'Num Patches'|sed 's/.*: //')
38 if [ "$upstreamnum" = "$(eval $*)" ]; then
39 echo "No remote changes to pull!"
40 exit 0
44 case $1 in
45 -h|--help)
46 usage
47 exit 0
49 -f)
50 format="$2"
51 shift 2
53 esac
55 [ -n "$format" ] || die "Target format is not given!"
57 case $format in
58 git|bzr|hg)
61 die "The requested target format is not yet supported!"
63 esac
65 origin="$1"
66 shift 1
68 [ -d "$origin" ] || die "Source repo does not exist!"
70 # convert to abspath
71 cd $origin
72 origin=$(pwd)
74 dmark="$origin.$format/darcs/dfe-marks"
75 fmark="$origin.$format/darcs/ffi-marks"
77 mkdir -p $origin.$format/darcs
78 cd $origin.$format
80 common_opts="--working $origin.$format/darcs/repo --logfile $origin.$format/darcs/log $origin"
81 if [ ! -f $dmark ]; then
82 case $format in
83 git)
84 git --bare init
85 darcs-fast-export $* --export-marks=$dmark $common_opts | \
86 git fast-import --export-marks=$fmark
88 bzr)
89 bzr init-repo .
90 darcs-fast-export $* --export-marks=$dmark $common_opts | \
91 bzr fast-import --export-marks=$fmark -
93 hg)
94 hg init
95 darcs-fast-export $* $origin | \
96 hg fastimport -
97 esac
98 else
99 case $format in
100 git)
101 check_up_to_date "git rev-list HEAD |wc -l"
102 darcs-fast-export $* --export-marks=$dmark --import-marks=$dmark $common_opts | \
103 git fast-import --export-marks=$fmark --import-marks=$fmark
105 bzr)
106 check_up_to_date "cd master; bzr revno"
107 darcs-fast-export $* --export-marks=$dmark --import-marks=$dmark $common_opts | \
108 bzr fast-import --export-marks=$fmark --import-marks=$fmark -
111 die "Incremental conversion to hg is not yet supported by hg fastimport."
113 esac