#!/bin/sh # # x2d - convert git, bzr or hg repos to darcs using fast-export # # Copyright (c) 2008 by Miklos Vajna # # 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 . # usage() { echo "Usage: x2d -f format repo" } die() { echo "$@" usage exit 1 } check_up_to_date() { upstreamnum=$(darcs show repo|grep 'Num Patches'|sed 's/.*: //') if [ "$upstreamnum" = "$(cd $origin; 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 "Source format is not given!" case $format in git|bzr|hg) ;; *) die "The requested source format is not yet supported!" ;; esac common_opts="" while [ -n "$2" ] do common_opts="$common_opts $1" shift 1 done origin="$1" shift 1 [ -d "$origin" ] || die "Source repo does not exist!" # convert to abspath cd $origin origin=$(pwd) dmark="$origin.darcs/_darcs/fast-import/dfe-marks" fmark="$origin.darcs/_darcs/fast-import/ffi-marks" mkdir -p $origin.darcs cd $origin.darcs common_opts="$common_opts --logfile $origin.darcs/_darcs/fast-import/log" pypath="/$(python -c 'from distutils import sysconfig; print sysconfig.get_python_lib()[1:]')/" if [ ! -f $dmark ]; then darcs init mkdir -p _darcs/fast-import case $format in git) (cd $origin; git fast-export --export-marks=$fmark HEAD) | \ darcs-fast-import --export-marks=$dmark $common_opts ;; bzr) (cd $origin; bzr fast-export \ --export-marks=$fmark . ) | darcs-fast-import --export-marks=$dmark $common_opts ;; hg) (cd $origin; $pypath/bzrlib/plugins/fastimport/exporters/hg-fast-export.py -r . ) | \ darcs-fast-import --export-marks=$dmark $common_opts esac else case $format in git) check_up_to_date "git rev-list HEAD |wc -l" (cd $origin; git fast-export --export-marks=$fmark --import-marks=$fmark HEAD) | \ darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts ;; bzr) # bzr revno is not good here, because at merges # it produces less revision than the number we # have in darcs check_up_to_date "bzr log --include-merges |grep -c revno:" (cd $origin; bzr fast-export \ --export-marks=$fmark --import-marks=$fmark . ) | \ darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts ;; hg) check_up_to_date 'echo $(($(hg tip --template "{rev}")+1))' (cd $origin; $pypath/bzrlib/plugins/fastimport/exporters/hg-fast-export.py -r . ) | \ darcs-fast-import --export-marks=$dmark --import-marks=$dmark $common_opts ;; esac fi