Added a description for my extensions (README-my-extensions.html).
[parsecvs/imz-RCS2git-use-cases.git] / RCS2git-use-cases / parsecvs-as-sidehist
blobf08530b945678c8e0e99a8278dbd76ecb26c5cf9
1 #!/bin/bash
3 # $Id$
4 # Description:
5 # Adds the result of parsecvs as a side history (with the specified prefix) to the local existing Git repository.
6 # I intend to use it for translating RCS histories for individual files into Git as independent histories (parseRCS-indep).
7 # I will manually merge the results of parseRCS-indep to form a good Git history of the tree
8 # (manual merging can give better results than parsecvs in cases when CVS hasn't been used, but there are merely RCS histories).
10 # Author: Ivan Zakharyaschev imz at altlinux dot org, March 2009.
11 # I publish it under GPLv2 or later (as parsecvs is published).
13 set -e
15 usage() {
16 printf $"Usage: %s REMOTENAME ... , where ... stands for parsecvs args.\n" "$0"
17 echo $"A sensible value for REMOTENAME is refs/remotes/PREFIX/... ."
20 if [[ $# < 1 ]]; then
21 usage
22 exit 1
24 case "$1" in
25 -h|--help|--usage)
26 usage
27 exit 0
29 esac
31 readonly REMOTE="$1"
32 shift
33 printf "%s will use %s as the ref to the new history.\n" "$0" "$REMOTE"
35 readonly WORK_DIR="$(mktemp -d --tmpdir parsecvs-"$(basename "$REMOTE")".XXXXXX)"
36 # -- basename is needed to make / possible in the branchnames.
37 # I'll remove the temp dir only if the script completes successfully;
38 # otherwise, let it stay for investigation.
39 failed() {
40 printf $"%s failed; investigate in %s.\n" "$0" "$WORK_DIR"
42 trap failed ERR
44 GIT_DIR="$WORK_DIR"/.git parsecvs "$@"
46 # Since I intend to use it multiple successive times for independent files (parseRCS-indep),
47 # I append the info about the fetched history to FETCH_HEAD.
48 # For cleanness, rm .git/FETCH_HEAD.
49 git fetch --append "$WORK_DIR" refs/heads/*:"$REMOTE"/*
50 # Sensible are: refs/PREFIX/... (then it can be seen in gitk),
51 # refs/remotes/PREFIX/... (then "git branch -a" shows it);
52 # one of these variants will be used in the wrapper that makes a forest.
54 printf $"The ref to the fetched history has been appended to FETCH_HEAD and stored as %s.\n" "$REMOTE"
56 echo $"Cleaning up:"
57 rm -rf "$WORK_DIR" && printf $"%s removed.\n" "$WORK_DIR"