diff --git a/hg2git.cf b/hg2git.cf index 15351b1..ff7f540 100644 --- a/hg2git.cf +++ b/hg2git.cf @@ -2,17 +2,17 @@ git clone --depth=1 --branch=master https://github.com/frej/fast-export.git curl "http://repo1.maven.org/maven2/com/madgag/bfg/1.12.15/bfg-1.12.15.jar" -o /bfg.jar cp {authors.py,users.csv} -mkdir +mkdir -# TO CREATE A GIT REPO AT FROM -cd -hg log | grep user: | sort | uniq | sed "s/user: *//" > /authors.txt -cd +# TO CREATE A GIT REPO AT FROM +cd +hg log | grep user: | sort | uniq | sed "s/user: *//" > /authors.txt +cd python /authors.py cp /* . git init git config core.ignoreCase false -sh hg-fast-export.sh -r --force -A reformatted-authors.txt +./hg-fast-export.sh -r --force -A reformatted-authors.txt git config --bool core.bare true # WARNING !!! @@ -22,15 +22,15 @@ git config --bool core.bare true # TO CLEAN UP LARGE FILES git gc -java -jar /bfg.jar --strip-blobs-bigger-than # == ~40M +java -jar /bfg.jar --strip-blobs-bigger-than # == ~40M git reflog expire --expire=now --all git gc --prune=now --aggressive # TO DELETE ALL CLOSED BRANCHES -cd -hg heads --closed --template "{branch}\n" | tr " " "_" | sort > /all.log -hg heads --template "{branch}\n" | tr " " "_" | sort > /open.log -cd +cd +hg heads --closed --template "{branch}\n" | tr " " "_" | sort > /all.log +hg heads --template "{branch}\n" | tr " " "_" | sort > /open.log +cd comm -2 -3 all.log open.log > closed.log for branch in `cat closed.log`; do git tag "closed/$branch" $branch; git branch -df $branch; done @@ -43,19 +43,25 @@ for file in `cat hgignore-files.log`; do sed -i.bak "s/syntax:/#syntax:/; s/^\^//; s/\$$//; s/\\\w\+/*/; s/\\\\\//\//g" $newfile; # optional done cat gitignore-files.log | xargs git add -git clean -df && git commit -m "Added gitignore files" && git push +git clean -df && git commit -m "Added gitignore files" + +# CLEANUP +rm -rfi * # removes everything except dotfiles!!! # OTHER TASKS * cloning non-bare mirror repo with all branches: - git clone --mirror /.git - cd + git clone --mirror /.git + cd git config --local --bool core.bare false git checkout master * cloning repo with a specific : - git clone -b --single-branch + git clone -b --single-branch * serving git repo git daemon --base-path=. --export-all --reuseaddr --informative-errors --verbose * URL: git://10.0.33.167/ * convert bare repo to non-bare - git config --bool core.bare true + git config --bool core.bare false git checkout master -f + +# NOTES +rm -rf com.visiercorp.vserver-git-bfg && git clone --mirror com.visiercorp.vserver-git com.visiercorp.vserver-git-bfg/.git && cd com.visiercorp.vserver-git-bfg && git gc && java -jar ../hg-git-migration/bfg.jar --strip-blobs-bigger-than 40M . && git reflog expire --expire=now --all && git gc --prune=now --aggressive diff --git a/hg2git.sh b/hg2git.sh new file mode 100755 index 0000000..db9f5fc --- /dev/null +++ b/hg2git.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +unset source +unset target +unset authors +unset fast_export + +source=$1 +target=$2 +authors=$3 +fast_export=$4 + +if [[ -z $source ]] || [[ -z $target ]] || [[ -z $authors ]] || [[ -z $fast_export ]]; then + echo "Some paths have not been set. Please provide all of the following: " + exit 1 +fi + +echo "Downloading hg-fast-export..." +rm -rf $fast_export +git clone --depth=1 --branch=master https://github.com/frej/fast-export.git $fast_export + +echo "Copying authors.py and users.csv..." +mkdir -p $authors && cp {authors.py,users.csv} $authors + +echo "Creating a list of authors from existing repository users..." +mkdir -p $target +cd $source +hg log | grep user: | sort | uniq | sed "s/user: *//" > $target/authors.txt +cd $target +python $authors/authors.py + +echo "Starting export with hg-fast-export..." +cp $fast_export/* . +git init +git config core.ignoreCase false +./hg-fast-export.sh -r $source --force -A reformatted-authors.txt +git config --bool core.bare true + +echo "All done! If you want to update this Git repository from the Hg repository, DO NOT DELETE ANY FILES FROM $target!!" +echo "To update this Git repository, run the hg2git_update.sh script." +echo "If you are absolutely sure you won't need to update this Git repository again, run the hg2git_clean.sh script to clean everything up." +echo "This script will strip large files, tag and delete closed branches, create .gitignore files, and delete temporary files." diff --git a/hg2git_clean.sh b/hg2git_clean.sh new file mode 100755 index 0000000..3c21b11 --- /dev/null +++ b/hg2git_clean.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +unset source +unset target +unset bfg_cleaner + +source=$1 +target=$2 +bfg_cleaner=$3 + +if [[ -z $source ]] || [[ -z $target ]] || [[ -z $bfg_cleaner ]]; then + echo "Some paths have not been set. Please provide all of the following: " + exit 1 +fi + +echo "Stripping out large files with BFG Repo-Cleaner..." +mkdir -p $bfg_cleaner +curl "http://repo1.maven.org/maven2/com/madgag/bfg/1.12.15/bfg-1.12.15.jar" -o $bfg_cleaner/bfg.jar +java -jar $bfg_cleaner/bfg.jar --strip-blobs-bigger-than 40M $target +git reflog expire --expire=now --all +git gc --prune=now --aggressive + +echo "Tagging and deleting closed branches..." +cd $source +hg heads --closed --template "{branch}\n" | tr " " "_" | sort > $target/all.log +hg heads --template "{branch}\n" | tr " " "_" | sort > $target/open.log +cd $target +comm -2 -3 all.log open.log > closed.log +for branch in `cat closed.log`; do git tag "closed/$branch" $branch; git branch -df $branch; done + +# TODO: Loop this for each open branch +echo "Creating .gitignore files from .hgignore files..." +find . -name ".hgignore" > hgignore-files.log +touch gitignore-files.log +for file in `cat hgignore-files.log`; do + newfile=${file/hgignore/gitignore}; + echo $newfile >> gitignore-files.log + cp $file $newfile; + sed -i.bak "s/syntax:/#syntax:/; s/^\^//; s/\$$//; s/\\\w\+/*/; s/\\\\\//\//g" $newfile; +done + +echo "All done! This Git repository is now ready to be pushed after the .gitignore files have been committed to the desired branches." diff --git a/hg2git_update.sh b/hg2git_update.sh new file mode 100755 index 0000000..9257acc --- /dev/null +++ b/hg2git_update.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +unset source +unset target +source=$1 +target=$2 + +if [[ -z $source ]] || [[ -z $target ]]; then + echo "Please provide the paths to the original Hg repository and the Git repository you wish to update!" + exit 1 +fi + +cd $target +./hg-fast-export.sh -r $source --force -A reformatted-authors.txt