summaryrefslogblamecommitdiffstats
path: root/repo-mutate.sh
blob: aa71ca43989487fc810e8c2c6cc456854da8413e (plain) (tree)
1
2
3
4
5
6
7
8
  
                          
 
                                                               



                                 



                          


  
                                                      

                                                                      
                                                                     
                                                                     
                             


                                 
                         
                                                            




               
 

                         



                








                                   
                    

      

                                
 



                                     
 
                                        
 



                                       





                                                                   
                                                                       



                                 
                                                            



               
                                               

                                      
                                                                

                                        
                                                                

                                        
                                                                

                                        
                                                                


              
                                        
 

  
                     






                                                                     
                                                  





                                            
##
# systr_repo_create_commit
#
# Create a new commit directory within the repository.  The new
# commit ID is printed to stdout.
##
function systr_repo_create_commit
{
    (
        cd "$path/revs/"
        mktemp -d XXXXXXXX
    )
}

##
# systr_repo_finish_commit <commit> <parent> [<merge>]
#
# Finish writing a commit by adding meta-data to the commit directory.
# The commit message is taken from the file <commit>.mesg at the root
# of the repository directory.  If <merge> is given, it is written to
# .merge.systr in the commit.
##
function systr_repo_finish_commit
{
    if [ $# -lt 2 ]; then
        echo "Fatal: too few args to repo_finish_commit" >&2
        exit 1
    fi

    commit="$1"
    parent="$2"

    if [ $# -gt 2 ]; then
        merge="$3"
    else
        merge=""
    fi

    if [ -f ".systr/author" ]; then
        read author <.systr/author
    else
        author="Anonymous"
    fi

    if [ -f ".systr/email" ]; then
        read email <.systr/email
    else
        email="anon"
    fi

    (
        cd "$path/revs/$commit/"

        echo "$parent" >.commit.systr
        echo "$author" >.author.systr
        echo "$email"  >.email.systr
        date >.date.systr

        mv "../$commit.mesg" .mesg.systr

        if [[ "$merge" != "" ]]; then
            echo "$merge" >.merge.systr
        fi
    )
}

##
# systr_repo_set_reference <symref> <commit>
#
# Update <symref> to point to <commit>.  If <symref> doesn't exist,
# it is created.  <commit> should not, itself, be a symbolic reference.
##
function systr_repo_set_reference
{
    if [ $# -lt 2 ]; then
        echo "Fatal: too few args to repo_set_reference" >&2
        exit 1
    fi

    symref="$1"
    commit=$(systr_repo_resolve_reference "$2")

    if [[ "$symref" == "BASE" ]]; then
        echo "Fatal: will not define BASE in the repository" >&2
        exit 1
    elif [[ "$symref" == "TRAC" ]]; then
        echo "Fatal: will not define TRAC in the repository" >&2
        exit 1
    elif [[ "$symref" == "NULL" ]]; then
        echo "Fatal: will not define NULL in the repository" >&2
        exit 1
    elif [[ "$symref" == "MERG" ]]; then
        echo "Fatal: will not define MERG in the repository" >&2
        exit 1
    fi

    echo "$commit" >"$path/refs/$symref"
}

##
# systrunk tag <name>
#
# Tag the current commit.  This creates a new branch which references
# BASE.
##
function systr_repo_tag
{
    if [ $# -lt 1 ]; then
        echo "Fatal: too few args to repo_tag" >&2
        exit 1
    fi

    name="$1"
    systr_repo_set_reference "$name" "$BASE"
}