From 972eb3c4e0edea9715eebaa264f3bc4b6699d90e Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 14:15:04 +0100 Subject: [PATCH 01/19] freebsd path --- git-svn-check-unpushed | 2 +- git-svn-clone-externals | 2 +- git-svn-externals-check | 2 +- git-svn-externals-update | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/git-svn-check-unpushed b/git-svn-check-unpushed index 8d6ddb8..72b018f 100755 --- a/git-svn-check-unpushed +++ b/git-svn-check-unpushed @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/local/bin/python from commands import getoutput import sys diff --git a/git-svn-clone-externals b/git-svn-clone-externals index d6896f8..a10c44b 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/local/bin/bash set -e diff --git a/git-svn-externals-check b/git-svn-externals-check index fddc313..bcfbe55 100755 --- a/git-svn-externals-check +++ b/git-svn-externals-check @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/local/bin/bash for dir in *; do if [ -d $dir ]; then diff --git a/git-svn-externals-update b/git-svn-externals-update index 4313b29..e0a0149 100755 --- a/git-svn-externals-update +++ b/git-svn-externals-update @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/local/bin/bash toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } From fcf487e715703bf952b1930be4620b134a3ff196 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 15:17:12 +0100 Subject: [PATCH 02/19] why use .git_externals since in first place, and in second place it can break virtual path in bsd makefiles --- git-svn-clone-externals | 21 +++++++++++---------- git-svn-externals-update | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index a10c44b..62d7fb0 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -16,14 +16,14 @@ function call() function do_clone() { - test -d .git_externals || return 1 + #test -d .git_externals || return 1 module=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'` branch=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,'|sed 's,^/,,'` if [[ $branch = $remote_url ]]; then branch="" fi ( - cd .git_externals + #cd .git_externals if [ -d "$local_directory" ]; then ( cd "$local_directory" @@ -71,10 +71,10 @@ function do_excludes() { dir="$1" git_excludes_path=.git/info/exclude - if ! grep -q '^.git_externals$' "$git_excludes_path" - then - echo .git_externals >> "$git_excludes_path" - fi + #if ! grep -q '^.git_externals$' "$git_excludes_path" + #then + # echo .git_externals >> "$git_excludes_path" + #fi if ! grep -q '^'"$dir"'$' "$git_excludes_path" then @@ -96,8 +96,9 @@ function is_excluded() } -git svn show-externals|grep -vE '#|^$'| \ - sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/'|while read -a words +git svn show-externals|grep -vE '#|^$' | \ + sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ + while read -a words do [ -z "${words[*]}" ] && continue @@ -126,10 +127,10 @@ do echo "$local_directory -> $remote_url" dir=`dirname $local_directory` - [ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" + #[ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" do_clone "$revision" "$remote_url" "$local_directory" || exit - do_link "$local_directory" + #do_link "$local_directory" do_excludes "$local_directory" fi diff --git a/git-svn-externals-update b/git-svn-externals-update index e0a0149..ea4ee1b 100755 --- a/git-svn-externals-update +++ b/git-svn-externals-update @@ -3,7 +3,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } -find .git_externals -type d -name .git | while read gitdir; do +find . -type d -name .git -depth 2 | while read gitdir; do dir=$(dirname "$gitdir") if [ -d $dir ]; then pushd $dir From 6455e4eb510c6c54f4b89811befabbd7b5a8c855 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 15:59:26 +0100 Subject: [PATCH 03/19] do what the README tells it should do --- git-svn-externals-check | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/git-svn-externals-check b/git-svn-externals-check index bcfbe55..1325df9 100755 --- a/git-svn-externals-check +++ b/git-svn-externals-check @@ -1,19 +1,24 @@ #!/usr/local/bin/bash -for dir in *; do + +toplevel_directory="$(git rev-parse --show-cdup)" +[ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } + +find . -type d -name .git -depth 2 | while read gitdir; do + dir=$(dirname "$gitdir") if [ -d $dir ]; then - cd $dir - STATUS=$(git status) - UNPUSHED=$(git-svn-check-unpushed) - if [ $(echo $STATUS|grep -c "clean") -lt 1 -o \ - $(echo $UNPUSHED|grep -c "No unpushed") -lt 1 ]; then - echo '>>>>>>>>>>>>>>>>' $dir '<<<<<<<<<<<<<<<<' - git status - git-svn-check-unpushed - echo '----------------------------------------' - else - echo $dir 'is clean' - fi - cd .. - fi + pushd $dir + STATUS=$(git status) + UNPUSHED=$(git-svn-check-unpushed) + if [ $(echo $STATUS|grep -c "clean") -lt 1 -o \ + $(echo $UNPUSHED|grep -c "No unpushed") -lt 1 ]; then + echo '>>>>>>>>>>>>>>>>' $dir '<<<<<<<<<<<<<<<<' + git status + git-svn-check-unpushed + echo '----------------------------------------' + else + echo $dir 'is clean' + fi + popd + fi done From 99d3b7efe2932f3d764718f6e6d65cfee571c2ba Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 16:02:22 +0100 Subject: [PATCH 04/19] remove unnecessary print --- git-svn-externals-check | 4 ++-- git-svn-externals-update | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/git-svn-externals-check b/git-svn-externals-check index 1325df9..ba49e36 100755 --- a/git-svn-externals-check +++ b/git-svn-externals-check @@ -7,7 +7,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" find . -type d -name .git -depth 2 | while read gitdir; do dir=$(dirname "$gitdir") if [ -d $dir ]; then - pushd $dir + pushd $dir 1>/dev/null 2>/dev/null STATUS=$(git status) UNPUSHED=$(git-svn-check-unpushed) if [ $(echo $STATUS|grep -c "clean") -lt 1 -o \ @@ -19,6 +19,6 @@ find . -type d -name .git -depth 2 | while read gitdir; do else echo $dir 'is clean' fi - popd + popd 1>/dev/null 2>/dev/null fi done diff --git a/git-svn-externals-update b/git-svn-externals-update index ea4ee1b..e65bd16 100755 --- a/git-svn-externals-update +++ b/git-svn-externals-update @@ -6,10 +6,10 @@ toplevel_directory="$(git rev-parse --show-cdup)" find . -type d -name .git -depth 2 | while read gitdir; do dir=$(dirname "$gitdir") if [ -d $dir ]; then - pushd $dir - echo $dir - git svn fetch - git svn rebase - popd + pushd $dir 1>/dev/null 2>/dev/null + echo $dir + git svn fetch + git svn rebase + popd 1>/dev/null 2>/dev/null fi done From edd8161225d8f47c1dc0119563c91f6b71c8b471 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 16:38:21 +0100 Subject: [PATCH 05/19] fix empty string + fix bash substitution pattern to replace only first match --- git-svn-check-unpushed | 9 +++++---- git-svn-clone-externals | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/git-svn-check-unpushed b/git-svn-check-unpushed index 72b018f..c562e0d 100755 --- a/git-svn-check-unpushed +++ b/git-svn-check-unpushed @@ -22,10 +22,11 @@ def list_references(): HEAD_ref = None refs = {} for item in references.split('\n'): - sha1, name = item.split() - if name == 'HEAD': - HEAD_ref = sha1 - refs[sha1] = name + if len(item) != 0: + sha1, name = item.split() + if name == 'HEAD': + HEAD_ref = sha1 + refs[sha1] = name return HEAD_ref, refs diff --git a/git-svn-clone-externals b/git-svn-clone-externals index 62d7fb0..af5047d 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -117,7 +117,7 @@ do if [ -n "$USE_SSH" ]; then echo "Rewriting url to use SVN+SSH." shopt -s extglob - remote_url="${remote_url/+(http|https)/svn+ssh}" + remote_url="${remote_url/#(http|https)/svn+ssh}" fi [ -z "${remote_url}" ] && continue From b5396ce4b7f4f0ba4ceb5745c2684ba06fd088a0 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 17:17:47 +0100 Subject: [PATCH 06/19] clarify reading --- git-svn-clone-externals | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index af5047d..9b6fbc6 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -96,7 +96,7 @@ function is_excluded() } -git svn show-externals|grep -vE '#|^$' | \ +git svn show-externals | grep -vE '#|^$' | \ sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ while read -a words do From 83e6d88e08547e4b11d935a9f1068b778e0c71c0 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 20:13:52 +0100 Subject: [PATCH 07/19] check for svn:externals in svn:externals --- git-svn-externals-check | 10 +++++++--- git-svn-externals-update | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/git-svn-externals-check b/git-svn-externals-check index ba49e36..2a23c13 100755 --- a/git-svn-externals-check +++ b/git-svn-externals-check @@ -4,7 +4,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } -find . -type d -name .git -depth 2 | while read gitdir; do +find . -type d -name .git -mindepth 2 | while read gitdir; do dir=$(dirname "$gitdir") if [ -d $dir ]; then pushd $dir 1>/dev/null 2>/dev/null @@ -13,8 +13,12 @@ find . -type d -name .git -depth 2 | while read gitdir; do if [ $(echo $STATUS|grep -c "clean") -lt 1 -o \ $(echo $UNPUSHED|grep -c "No unpushed") -lt 1 ]; then echo '>>>>>>>>>>>>>>>>' $dir '<<<<<<<<<<<<<<<<' - git status - git-svn-check-unpushed + cat >&1 << EOF +$STATUS +EOF + cat >&1 << EOF +$UNPUSHED +EOF echo '----------------------------------------' else echo $dir 'is clean' diff --git a/git-svn-externals-update b/git-svn-externals-update index e65bd16..4748ec4 100755 --- a/git-svn-externals-update +++ b/git-svn-externals-update @@ -3,7 +3,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } -find . -type d -name .git -depth 2 | while read gitdir; do +find . -type d -name .git -mindepth 2 | while read gitdir; do dir=$(dirname "$gitdir") if [ -d $dir ]; then pushd $dir 1>/dev/null 2>/dev/null From c21c18e62a6f015ec6e6d0247cf21cbbe1af6b95 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Thu, 8 Dec 2011 20:38:08 +0100 Subject: [PATCH 08/19] recurse for svn:externals --- git-svn-clone-externals | 82 +++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index 9b6fbc6..3a39369 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -17,8 +17,11 @@ function call() function do_clone() { #test -d .git_externals || return 1 - module=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'` - branch=`echo $remote_url|sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,'|sed 's,^/,,'` + revision="$1" + remote_url="$2" + local_directory="$3" + module=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'` + branch=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,' | sed 's,^/,,'` if [[ $branch = $remote_url ]]; then branch="" fi @@ -32,9 +35,9 @@ function do_clone() else tags="tags" brch="branches" - branchpath=$(echo $branch|cut -f1 -d/) - echo $tags|grep $branchpath >/dev/null 2>&1 && tags=$branchpath - echo $brch|grep $branchpath >/dev/null 2>&1 && brch=$branchpath + branchpath=$(echo $branch | cut -f1 -d/) + echo $tags | grep $branchpath >/dev/null 2>&1 && tags=$branchpath + echo $brch | grep $branchpath >/dev/null 2>&1 && brch=$branchpath if [ "$module" = "$remote_url" ]; then # URL does not contains any trunk, branches or tags part, so we dont need @@ -46,7 +49,7 @@ function do_clone() fi ( - branch="$(echo ${branch}|sed 's,/$,,')" + branch="$(echo ${branch} | sed 's,/$,,')" if [ -n "$branch" ]; then cd "$local_directory" call git reset --hard $branch @@ -86,7 +89,7 @@ function is_excluded() { local result=0 if [ -f .git_externals_exclude ] ; then - matches=`grep -v "^#" .git_externals_exclude|grep "^/$1$"|wc -l` + matches=`grep -v "^#" .git_externals_exclude | grep "^/$1$"|wc -l` if [ $matches -gt 0 ] ; then local result=1 fi @@ -96,43 +99,52 @@ function is_excluded() } -git svn show-externals | grep -vE '#|^$' | \ - sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ +function do_clone_externals() +{ + git svn show-externals | grep -vE '#|^$' | \ + sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ while read -a words -do - [ -z "${words[*]}" ] && continue + do + [ -z "${words[*]}" ] && continue - local_directory="$(echo ${words[0]}|sed 's,^/,,')" - revision="" - remote_url="${words[1]}" + local_directory="$(echo ${words[0]} | sed 's,^/,,')" + revision="" + remote_url="${words[1]}" - check_excluded=$(is_excluded $local_directory) + check_excluded=$(is_excluded $local_directory) - if [ $check_excluded -eq 0 ] ; then - if [ -n "${words[2]}" ]; then - revision="${words[1]}" - remote_url="${words[2]}" - fi + if [ $check_excluded -eq 0 ] ; then + if [ -n "${words[2]}" ]; then + revision="${words[1]}" + remote_url="${words[2]}" + fi - if [ -n "$USE_SSH" ]; then - echo "Rewriting url to use SVN+SSH." - shopt -s extglob - remote_url="${remote_url/#(http|https)/svn+ssh}" - fi + if [ -n "$USE_SSH" ]; then + echo "Rewriting url to use SVN+SSH." + shopt -s extglob + remote_url="${remote_url/#(http|https)/svn+ssh}" + fi - [ -z "${remote_url}" ] && continue + [ -z "${remote_url}" ] && continue - export local_directory revision remote_url + #export local_directory revision remote_url - echo "$local_directory -> $remote_url" + echo "$local_directory -> $remote_url" - dir=`dirname $local_directory` - #[ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" + dir=`dirname $local_directory` + #[ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" - do_clone "$revision" "$remote_url" "$local_directory" || exit - #do_link "$local_directory" - do_excludes "$local_directory" - fi + do_clone "$revision" "$remote_url" "$local_directory" || exit + #do_link "$local_directory" + do_excludes "$local_directory" -done + #recurse svn:externals + pushd $local_directory 1>/dev/null 2>/dev/null + do_clone_externals + popd 1>/dev/null 2>/dev/null + fi + + done +} +do_clone_externals From ef5147cf4ab66325c86377609dfc8325f0237efc Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 09:49:05 +0100 Subject: [PATCH 09/19] git ignore file featured option --- git-svn-clone-externals | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index 3a39369..009ae5e 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -5,6 +5,7 @@ set -e toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } +gitignore_file="" function call() { @@ -145,6 +146,49 @@ function do_clone_externals() fi done + + if [ -n "$gitignore_file" ]; then + cat $gitignore_file >> .git/info/exclude + fi } +function usage() +{ + echo "Usage: `basename $0` [-i git-ignore-file]" + echo " -i git-ignore-file : git-ignore-file must exist. $0 will add its content to exclude informations" + exit 2 +} + +args=`getopt i: $*` +ret=$? +if [ $ret -ne 0 ]; then + usage +fi +set -- $args + +for _a; do + case "$_a" in + -i) + _ignorefile="$2" + shift + shift + ;; + --) + shift + break + ;; + esac +done + +if [ -n "$_ignorefile" -a ! -f "$_ignorefile" ]; then + usage +fi +if [ -n "$_ignorefile" ]; then + _ignorefile=`realpath -q $_ignorefile` + if [ $? -ne 0 ]; then + usage + fi +fi +gitignore_file="$_ignorefile" + do_clone_externals From 6ee5f5133885f33970f46541add8bd4dfb8575ee Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 10:23:45 +0100 Subject: [PATCH 10/19] use getopts (bash) instead of getopt (sh) + featured option to use symlinks --- git-svn-clone-externals | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index 009ae5e..ea5fe9b 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -6,6 +6,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } gitignore_file="" +use_symlinks=0 function call() { @@ -17,7 +18,9 @@ function call() function do_clone() { - #test -d .git_externals || return 1 + if [ $use_symlinks -ne 0 ]; then + test -d .git_externals || return 1 + fi revision="$1" remote_url="$2" local_directory="$3" @@ -27,7 +30,9 @@ function do_clone() branch="" fi ( - #cd .git_externals + if [ $use_symlinks -ne 0 ]; then + cd .git_externals + fi if [ -d "$local_directory" ]; then ( cd "$local_directory" @@ -75,11 +80,12 @@ function do_excludes() { dir="$1" git_excludes_path=.git/info/exclude - #if ! grep -q '^.git_externals$' "$git_excludes_path" - #then - # echo .git_externals >> "$git_excludes_path" - #fi - + if [ $use_symlinks -ne 0 ]; then + if ! grep -q '^.git_externals$' "$git_excludes_path" + then + echo .git_externals >> "$git_excludes_path" + fi + fi if ! grep -q '^'"$dir"'$' "$git_excludes_path" then echo "$dir" >> "$git_excludes_path" @@ -128,15 +134,17 @@ function do_clone_externals() [ -z "${remote_url}" ] && continue - #export local_directory revision remote_url - echo "$local_directory -> $remote_url" dir=`dirname $local_directory` - #[ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" + if [ $use_symlinks -ne 0 ]; then + [ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" + fi do_clone "$revision" "$remote_url" "$local_directory" || exit - #do_link "$local_directory" + if [ $use_symlinks -ne 0 ]; then + do_link "$local_directory" + fi do_excludes "$local_directory" #recurse svn:externals @@ -154,28 +162,24 @@ function do_clone_externals() function usage() { - echo "Usage: `basename $0` [-i git-ignore-file]" + echo "Usage: `basename $0` [-i git-ignore-file] [-l]" echo " -i git-ignore-file : git-ignore-file must exist. $0 will add its content to exclude informations" + echo " -l : use symlinks to svn:externals repositories (default: off)" exit 2 } -args=`getopt i: $*` -ret=$? -if [ $ret -ne 0 ]; then - usage -fi -set -- $args - -for _a; do - case "$_a" in - -i) - _ignorefile="$2" - shift - shift +# Main + +while getopts "li:" _a; do + case $_a in + i) + _ignorefile="$OPTARG" + ;; + l) + use_symlinks=1 ;; - --) - shift - break + \?) + usage ;; esac done From 661cac4af5a9c70d3eaea83a7edce495a9b3e5bc Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 10:33:50 +0100 Subject: [PATCH 11/19] README --- README.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.txt b/README.txt index 2578b06..72c0b69 100644 --- a/README.txt +++ b/README.txt @@ -80,3 +80,11 @@ Options - Alexander Artemenko +* -i git-ignore-file : For some reason, I need to add some ignore to the root repository + and to each svn:externals project. the git-ignore-file format is just like a .gitignore + file format. Its content will be added to .git/info/exclude for each repository. +* -l : use symlinks in .git_externals/ for each svn:externals repository. The default is + off, which means it does not create symlinks, but direct folder in the main repository. + Everything should just work the same with modified scripts from this 'freebsd' branch. + +- Guillaume Bibaut From fd90c9b93d890c770ac9f6ad1076b030be0f717d Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 10:37:11 +0100 Subject: [PATCH 12/19] README --- README.txt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.txt b/README.txt index 72c0b69..898401c 100644 --- a/README.txt +++ b/README.txt @@ -80,11 +80,17 @@ Options - Alexander Artemenko -* -i git-ignore-file : For some reason, I need to add some ignore to the root repository - and to each svn:externals project. the git-ignore-file format is just like a .gitignore - file format. Its content will be added to .git/info/exclude for each repository. -* -l : use symlinks in .git_externals/ for each svn:externals repository. The default is - off, which means it does not create symlinks, but direct folder in the main repository. - Everything should just work the same with modified scripts from this 'freebsd' branch. +* git-svn-clone-externals + * -i git-ignore-file : For some reason, I need to add some ignore to the root repository + and to each svn:externals project. the git-ignore-file format is just like a .gitignore + file format. Its content will be added to .git/info/exclude for each repository. + * -l : use symlinks in .git_externals/ for each svn:externals repository. The default is + off, which means it does not create symlinks, but direct folder in the main repository. + Everything should just work the same with modified scripts from this 'freebsd' branch. + * Recursive svn:externals clone: + RootRepo/ + + ExtRepo1/ (svn:externals in RootRepo/) + | + ExtRepo11/ (svn:externals in ExtRepo1/) + ... - Guillaume Bibaut From 071f1cce5208c8c433f146ec422d60a55bdfc371 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 10:49:48 +0100 Subject: [PATCH 13/19] indentation with spaces --- git-svn-clone-externals | 200 ++++++++++++++++++++-------------------- git-svn-externals-check | 2 +- 2 files changed, 101 insertions(+), 101 deletions(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index ea5fe9b..c16cbfa 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -10,86 +10,86 @@ use_symlinks=0 function call() { - cmd="$@" - echo "$cmd" - eval "$cmd" - return "$?" + cmd="$@" + echo "$cmd" + eval "$cmd" + return "$?" } function do_clone() { if [ $use_symlinks -ne 0 ]; then - test -d .git_externals || return 1 + test -d .git_externals || return 1 fi revision="$1" remote_url="$2" local_directory="$3" - module=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'` - branch=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,' | sed 's,^/,,'` - if [[ $branch = $remote_url ]]; then - branch="" - fi - ( - if [ $use_symlinks -ne 0 ]; then - cd .git_externals + module=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\1,'` + branch=`echo $remote_url | sed 's,\(.*\)\(/trunk\|/branch.*\|/tag.*\),\2,' | sed 's,^/,,'` + if [[ $branch = $remote_url ]]; then + branch="" + fi + ( + if [ $use_symlinks -ne 0 ]; then + cd .git_externals + fi + if [ -d "$local_directory" ]; then + ( + cd "$local_directory" + call git svn fetch --all + ) + else + tags="tags" + brch="branches" + branchpath=$(echo $branch | cut -f1 -d/) + echo $tags | grep $branchpath >/dev/null 2>&1 && tags=$branchpath + echo $brch | grep $branchpath >/dev/null 2>&1 && brch=$branchpath + + if [ "$module" = "$remote_url" ]; then + # URL does not contains any trunk, branches or tags part, so we dont need + # additional options for git-svn + call git svn clone "$revision" "$module" "$local_directory" + else + call git svn clone "$revision" "$module" -T trunk -b $brch -t $tags "$local_directory" fi - if [ -d "$local_directory" ]; then - ( - cd "$local_directory" - call git svn fetch --all - ) - else - tags="tags" - brch="branches" - branchpath=$(echo $branch | cut -f1 -d/) - echo $tags | grep $branchpath >/dev/null 2>&1 && tags=$branchpath - echo $brch | grep $branchpath >/dev/null 2>&1 && brch=$branchpath - - if [ "$module" = "$remote_url" ]; then - # URL does not contains any trunk, branches or tags part, so we dont need - # additional options for git-svn - call git svn clone "$revision" "$module" "$local_directory" - else - call git svn clone "$revision" "$module" -T trunk -b $brch -t $tags "$local_directory" - fi - - fi - ( - branch="$(echo ${branch} | sed 's,/$,,')" - if [ -n "$branch" ]; then - cd "$local_directory" - call git reset --hard $branch - fi - ) - ) + + fi + ( + branch="$(echo ${branch} | sed 's,/$,,')" + if [ -n "$branch" ]; then + cd "$local_directory" + call git reset --hard $branch + fi + ) + ) } function do_link() { - dir="$1" - base="$(dirname $dir)" - ( - mkdir -p "$base" - cd $base - rel=$(git rev-parse --show-cdup) - ln -sf ${rel}.git_externals/"$dir" - ) + dir="$1" + base="$(dirname $dir)" + ( + mkdir -p "$base" + cd $base + rel=$(git rev-parse --show-cdup) + ln -sf ${rel}.git_externals/"$dir" + ) } function do_excludes() { - dir="$1" - git_excludes_path=.git/info/exclude + dir="$1" + git_excludes_path=.git/info/exclude if [ $use_symlinks -ne 0 ]; then - if ! grep -q '^.git_externals$' "$git_excludes_path" + if ! grep -q '^.git_externals$' "$git_excludes_path" then echo .git_externals >> "$git_excludes_path" fi fi - if ! grep -q '^'"$dir"'$' "$git_excludes_path" - then - echo "$dir" >> "$git_excludes_path" - fi + if ! grep -q '^'"$dir"'$' "$git_excludes_path" + then + echo "$dir" >> "$git_excludes_path" + fi } function is_excluded() @@ -109,51 +109,51 @@ function is_excluded() function do_clone_externals() { git svn show-externals | grep -vE '#|^$' | \ - sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ - while read -a words - do - [ -z "${words[*]}" ] && continue - - local_directory="$(echo ${words[0]} | sed 's,^/,,')" - revision="" - remote_url="${words[1]}" - - check_excluded=$(is_excluded $local_directory) - - if [ $check_excluded -eq 0 ] ; then - if [ -n "${words[2]}" ]; then - revision="${words[1]}" - remote_url="${words[2]}" + sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ + while read -a words + do + [ -z "${words[*]}" ] && continue + + local_directory="$(echo ${words[0]} | sed 's,^/,,')" + revision="" + remote_url="${words[1]}" + + check_excluded=$(is_excluded $local_directory) + + if [ $check_excluded -eq 0 ] ; then + if [ -n "${words[2]}" ]; then + revision="${words[1]}" + remote_url="${words[2]}" + fi + + if [ -n "$USE_SSH" ]; then + echo "Rewriting url to use SVN+SSH." + shopt -s extglob + remote_url="${remote_url/#(http|https)/svn+ssh}" + fi + + [ -z "${remote_url}" ] && continue + + echo "$local_directory -> $remote_url" + + dir=`dirname $local_directory` + if [ $use_symlinks -ne 0 ]; then + [ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" + fi + + do_clone "$revision" "$remote_url" "$local_directory" || exit + if [ $use_symlinks -ne 0 ]; then + do_link "$local_directory" + fi + do_excludes "$local_directory" + + #recurse svn:externals + pushd $local_directory 1>/dev/null 2>/dev/null + do_clone_externals + popd 1>/dev/null 2>/dev/null fi - if [ -n "$USE_SSH" ]; then - echo "Rewriting url to use SVN+SSH." - shopt -s extglob - remote_url="${remote_url/#(http|https)/svn+ssh}" - fi - - [ -z "${remote_url}" ] && continue - - echo "$local_directory -> $remote_url" - - dir=`dirname $local_directory` - if [ $use_symlinks -ne 0 ]; then - [ -d ".git_externals/$dir" ] || mkdir -p ".git_externals/$dir" - fi - - do_clone "$revision" "$remote_url" "$local_directory" || exit - if [ $use_symlinks -ne 0 ]; then - do_link "$local_directory" - fi - do_excludes "$local_directory" - - #recurse svn:externals - pushd $local_directory 1>/dev/null 2>/dev/null - do_clone_externals - popd 1>/dev/null 2>/dev/null - fi - - done + done if [ -n "$gitignore_file" ]; then cat $gitignore_file >> .git/info/exclude diff --git a/git-svn-externals-check b/git-svn-externals-check index 2a23c13..7664d2a 100755 --- a/git-svn-externals-check +++ b/git-svn-externals-check @@ -5,7 +5,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } find . -type d -name .git -mindepth 2 | while read gitdir; do - dir=$(dirname "$gitdir") + dir=$(dirname "$gitdir") if [ -d $dir ]; then pushd $dir 1>/dev/null 2>/dev/null STATUS=$(git status) From 5511814d52c71df2d6e16ef8833c4cf70c1824b5 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Fri, 9 Dec 2011 14:11:33 +0100 Subject: [PATCH 14/19] Fix issue #1: do not add git ignore options again and again, based on git ignore file name --- git-svn-clone-externals | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index c16cbfa..22bdcd9 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -156,7 +156,11 @@ function do_clone_externals() done if [ -n "$gitignore_file" ]; then - cat $gitignore_file >> .git/info/exclude + _base=$(basename $gitignore_file) + if ! grep -q "^# $_base$" .git/info/exclude; then + echo "# $_base" >> .git/info/exclude + cat $gitignore_file >> .git/info/exclude + fi fi } From ef4ad68adf43a6e310a81dd4c3177da6f488251b Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Sun, 11 Dec 2011 19:36:57 +0100 Subject: [PATCH 15/19] feature to add git exclude pattern to each svn:externals without dups --- git-svn-excludes-update | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 git-svn-excludes-update diff --git a/git-svn-excludes-update b/git-svn-excludes-update new file mode 100755 index 0000000..fbc612d --- /dev/null +++ b/git-svn-excludes-update @@ -0,0 +1,88 @@ +#!/usr/local/bin/bash + +set -e + +toplevel_directory="$(git rev-parse --show-cdup)" +[ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } + +gitignore_file="" + +function is_excluded() +{ + local result=0 + if [ -f .git_externals_exclude ] ; then + matches=`grep -v "^#" .git_externals_exclude | grep "^/$1$"|wc -l` + if [ $matches -gt 0 ] ; then + local result=1 + fi + fi + echo $result + return +} + + +function do_excludes_update() +{ + _root="$1" + git svn show-externals | grep -vE '#|^$' | \ + sed 's/\(-r\)[ ]*\([0-9]\{1,\}\)/\1\2/' | \ + while read -a words; do + [ -z "${words[*]}" ] && continue + + local_directory="$(echo ${words[0]} | sed 's,^/,,')" + [ -z "$local_directory" ] && continue + + check_excluded=$(is_excluded $local_directory) + if [ $check_excluded -eq 0 ] ; then + #recurse svn:externals + pushd $local_directory 2>&1 >/dev/null + do_excludes_update $_root + popd 2>&1 >/dev/null + fi + + done + + _pwd=`pwd` + _pwd="${_pwd/${_root}/}" + echo ".${_pwd}" + cat $gitignore_file | while read excopt; do + if ! grep -q "^${excopt}" .git/info/exclude; then + echo " adding \"${excopt}\" exclude pattern" + cat >> .git/info/exclude << EOF +${excopt} +EOF + fi + done +} + +function usage() +{ + echo "Usage: `basename $0` -i git-ignore-file" + echo " -i git-ignore-file : git-ignore-file must exist. $0 will add its content to exclude informations" + exit 2 +} + +# Main + +while getopts "i:" _a; do + case $_a in + i) + _ignorefile="$OPTARG" + ;; + \?) + usage + ;; + esac +done + +if [ -z "$_ignorefile" -o ! -f "$_ignorefile" ]; then + usage +fi +_ignorefile=`realpath -q $_ignorefile` +if [ $? -ne 0 ]; then + usage +fi +gitignore_file="$_ignorefile" + +_root=`pwd` +do_excludes_update $_root From 27e2f909b267626a7d94a103f42fb1fafe0c7e0e Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Sun, 11 Dec 2011 20:30:42 +0100 Subject: [PATCH 16/19] better check and use of git exclude patterns --- git-svn-clone-externals | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/git-svn-clone-externals b/git-svn-clone-externals index 22bdcd9..71844eb 100755 --- a/git-svn-clone-externals +++ b/git-svn-clone-externals @@ -156,11 +156,14 @@ function do_clone_externals() done if [ -n "$gitignore_file" ]; then - _base=$(basename $gitignore_file) - if ! grep -q "^# $_base$" .git/info/exclude; then - echo "# $_base" >> .git/info/exclude - cat $gitignore_file >> .git/info/exclude - fi + cat $gitignore_file | while read excopt; do + if ! grep -q "^${excopt}" .git/info/exclude; then + echo " adding \"${excopt}\" exclude pattern" + cat >> .git/info/exclude << EOF +${excopt} +EOF + fi + done fi } From 88e54ba9de6d9b97e65246970207ecb80367b6d3 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Sun, 11 Dec 2011 20:35:46 +0100 Subject: [PATCH 17/19] indentation with spaces --- git-svn-externals-update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svn-externals-update b/git-svn-externals-update index 4748ec4..1215b99 100755 --- a/git-svn-externals-update +++ b/git-svn-externals-update @@ -4,7 +4,7 @@ toplevel_directory="$(git rev-parse --show-cdup)" [ -n "$toplevel_directory" ] && { echo "please run from the toplevel directory"; exit 1; } find . -type d -name .git -mindepth 2 | while read gitdir; do - dir=$(dirname "$gitdir") + dir=$(dirname "$gitdir") if [ -d $dir ]; then pushd $dir 1>/dev/null 2>/dev/null echo $dir From a330858e595a94b8f721b5d3bea074a68dfc9284 Mon Sep 17 00:00:00 2001 From: Guillaume Bibaut Date: Sun, 11 Dec 2011 20:41:34 +0100 Subject: [PATCH 18/19] new command added --- README.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 898401c..e50c8a8 100644 --- a/README.txt +++ b/README.txt @@ -80,7 +80,7 @@ Options - Alexander Artemenko -* git-svn-clone-externals +* ``git-svn-clone-externals`` * -i git-ignore-file : For some reason, I need to add some ignore to the root repository and to each svn:externals project. the git-ignore-file format is just like a .gitignore file format. Its content will be added to .git/info/exclude for each repository. @@ -93,4 +93,15 @@ Options | + ExtRepo11/ (svn:externals in ExtRepo1/) ... +* ``git-svn-excludes-update`` + * -i git-ignore-file : this options is required for this script. For each exclude pattern + option in the file, the script will check if it exists in .git/info/exclude. The script + check each svn:externals recursively. + git-ignore-file sample : + $ cat git-ignore-file + *.o + *.a + *~ + # end-of-file + - Guillaume Bibaut From 3e2ca348dad70ad90c39c4cac0cab1744034869e Mon Sep 17 00:00:00 2001 From: Guillaume BIBAUT Date: Fri, 16 Mar 2012 07:59:25 +0100 Subject: [PATCH 19/19] end of line fix --- README.txt | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.txt b/README.txt index e50c8a8..f691daf 100644 --- a/README.txt +++ b/README.txt @@ -81,12 +81,14 @@ Options - Alexander Artemenko * ``git-svn-clone-externals`` - * -i git-ignore-file : For some reason, I need to add some ignore to the root repository - and to each svn:externals project. the git-ignore-file format is just like a .gitignore - file format. Its content will be added to .git/info/exclude for each repository. - * -l : use symlinks in .git_externals/ for each svn:externals repository. The default is - off, which means it does not create symlinks, but direct folder in the main repository. - Everything should just work the same with modified scripts from this 'freebsd' branch. + * -i git-ignore-file : For some reason, I need to add some ignore to + the root repository and to each svn:externals project. the git-ignore-file + format is just like a .gitignore file format. Its content will be added to + .git/info/exclude for each repository. + * -l : use symlinks in .git_externals/ for each svn:externals repository. + The default is off, which means it does not create symlinks, but direct + folder in the main repository. Everything should just work the same with + modified scripts from this 'freebsd' branch. * Recursive svn:externals clone: RootRepo/ + ExtRepo1/ (svn:externals in RootRepo/) @@ -94,9 +96,9 @@ Options ... * ``git-svn-excludes-update`` - * -i git-ignore-file : this options is required for this script. For each exclude pattern - option in the file, the script will check if it exists in .git/info/exclude. The script - check each svn:externals recursively. + * -i git-ignore-file : this options is required for this script. For each + exclude pattern option in the file, the script will check if it exists in + .git/info/exclude. The script check each svn:externals recursively. git-ignore-file sample : $ cat git-ignore-file *.o