mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
major update
This commit is contained in:
parent
cc7d4c8bd7
commit
ca5fc7c582
15 changed files with 562 additions and 68 deletions
174
scripts/nix-statecommit.sh
Executable file
174
scripts/nix-statecommit.sh
Executable file
|
|
@ -0,0 +1,174 @@
|
|||
#! /bin/sh
|
||||
# we cant do a -e since ... svn can fail ??? TODO...
|
||||
|
||||
#check if there are enough arguments, if not, exit with an error
|
||||
|
||||
debug=""; #set to "" for no debugging, set to "echo " to debug the commands
|
||||
|
||||
if [ "$#" != 5 ] && [ "$#" != 6 ] ; then
|
||||
echo "Incorrect number of arguments"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "$deletesvn" != "" ] && [ "$deletesvn" != "1" ]; then
|
||||
echo "The last argument (DELETE svn folders) must be either empty (recommended) or 1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
svnbin=$1
|
||||
subversionedpaths=( $2 ) #arrays
|
||||
subversionedpathsCommitBools=( $3 )
|
||||
nonversionedpaths=( $4 )
|
||||
checkouts=( $5 )
|
||||
deletesvn=$6 #this flag can be set to 1 to DELETE all .svn folders and NOT commit
|
||||
|
||||
|
||||
if [ "$debug" != "" ] ; then
|
||||
echo svnbin: $svnbin
|
||||
echo subversionedpaths: ${subversionedpaths[@]}
|
||||
echo subversionedpathsCommitBools: ${subversionedpathsCommitBools[@]}
|
||||
echo nonversionedpaths: ${nonversionedpaths[@]}
|
||||
echo checkouts: ${checkouts[@]}
|
||||
echo deletesvn: $deletesvn
|
||||
fi
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
function subversionSingleStateDir {
|
||||
|
||||
excludelist=( "." ".." ".svn" );
|
||||
|
||||
cd $1;
|
||||
#echo cd $1;
|
||||
|
||||
empty=$(ls)
|
||||
|
||||
if [ "$empty" = "" ] ; then
|
||||
allsubitems=(); #no subfiles / dirs
|
||||
else
|
||||
allsubitems=( $(echo *) $(echo .*) ) #there are subfiles / dirs,also adds hidden items
|
||||
fi
|
||||
|
||||
for subitem in ${allsubitems[@]}
|
||||
do
|
||||
if [ "$subitem" = ".svn" ]; then
|
||||
allsubitems=( $(svn -N stat | sed -n '/^?/p' | sed 's/? //' | tr -d "\12") ) #there are subfiles, and theyre already versioned
|
||||
|
||||
if [ "$deletesvn" = "1" ]; then
|
||||
rm -rf .svn/
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
#echo "Allsubitems ${allsubitems[@]}"
|
||||
|
||||
subitems=();
|
||||
for subitem in ${allsubitems[@]} #add all, were going to exlucde explicity stated direct versioned-subdirs or explicity stated nonversioned-subdirs
|
||||
do #this is only to prevent some warnings, ultimately we would like svn add to have a option 'exclude dirs'
|
||||
|
||||
exclude=0;
|
||||
|
||||
for excl in ${excludelist[@]} #check if the subitem is in the list of excluded dirs
|
||||
do
|
||||
if [ "$excl" = "$subitem" ]; then
|
||||
exclude=1;
|
||||
#echo "exclude $excl"
|
||||
fi
|
||||
done
|
||||
|
||||
subitem="$(pwd)/$subitem"; #create the full path
|
||||
|
||||
if test -d $subitem; then #the subitem (file or a dir) may be a dir, so we add a / to the end
|
||||
subitem="$subitem/";
|
||||
fi
|
||||
|
||||
for svnp in ${subversionedpaths[@]} #check if the subitem is in the list of subverioned paths
|
||||
do
|
||||
if [ "$svnp" = "$subitem" ]; then
|
||||
exclude=1;
|
||||
#echo "exclude versioned $svnp"
|
||||
fi
|
||||
done
|
||||
|
||||
for nonvp in ${nonversionedpaths[@]} #check if the subitem is in the list of dirs that aren't supposed to be versioned
|
||||
do
|
||||
if [ "$nonvp" = "$subitem" ]; then
|
||||
exclude=1;
|
||||
#echo "exclude nonversioned $svnp"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $exclude = 0 ]; then #Exclude the subitem if nessecary
|
||||
subitems[${#subitems[*]}]=$subitem
|
||||
fi
|
||||
done
|
||||
|
||||
#echo ${subitems[@]}
|
||||
|
||||
for item in ${subitems[@]}
|
||||
do
|
||||
if test -d $item; then #add or go recursive subitems
|
||||
if [ "$deletesvn" != "1" ]; then
|
||||
$debug svn -N add $item #NON recursively add the dir
|
||||
fi
|
||||
subversionSingleStateDir $item
|
||||
else
|
||||
if [ "$deletesvn" != "1" ]; then
|
||||
$debug svn add $item
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
i=0
|
||||
i_checkout=0
|
||||
for path in ${subversionedpaths[@]}
|
||||
do
|
||||
if test -d $path; then #if the dir doesnt exist, than we dont hav to do anything
|
||||
cd $path;
|
||||
|
||||
checkoutcommand=""; #HACK: I cant seem to find a way for bash to parse a 2 dimensional string array as argument, so we use a 1-d array with '|' as seperator
|
||||
while true; do
|
||||
if [ "${checkouts[$i_checkout]}" = "|" ]; then
|
||||
let "i_checkout+=1"
|
||||
break
|
||||
fi
|
||||
checkoutcommand="${checkoutcommand} ${checkouts[$i_checkout]}";
|
||||
let "i_checkout+=1"
|
||||
done
|
||||
|
||||
if ! test -d "${path}.svn/"; then #if the dir exists but is not yet an svn dir: checkout repos, if it doenst exits (is removed or something) than we dont do anything
|
||||
if [ "$deletesvn" != "1" ]; then
|
||||
$debug $checkoutcommand;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${subversionedpathsCommitBools[$i]}" = "true" ]; then #Check if we need to commit this folder
|
||||
|
||||
echo "Entering $path"
|
||||
|
||||
subversionSingleStateDir $path;
|
||||
|
||||
cd $path #now that everything is added we go back to the 'root' path and commit
|
||||
if [ "$deletesvn" != "1" ]; then
|
||||
$debug svn -m "" commit;
|
||||
fi
|
||||
fi
|
||||
|
||||
cd - &> /dev/null;
|
||||
let "i+=1"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue