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




                                     
                                                                


              
            
 




                                            
                   
        


                      



                                                       
                
                                                 


                      

      



                              

                                                                
  
                  






                                                   







                                      
 


                                                   

                   
         
 














                                                              
      







                          
 
##
# systr_repo_resolve_reference <ref>
#
# Resolve a revision name to a commit ID.  The result is printed to
# stdout.
##
function systr_repo_resolve_reference
{
    if [ $# -lt 1 ]; then
        echo "Fatal: too few args to repo_resolve_reference" >&2
        exit 1
    fi

    ref="$1"

    if [[ "$ref" == "BASE" ]]; then
        cat .systr/BASE
    elif [[ "$ref" == "TRAC" ]]; then
        systr_repo_resolve_reference "$TRAC"
    elif [[ "$ref" == "NULL" ]]; then
        echo "NULL"
    else
        (
            cd "$path"

            if [ -f "refs/$ref" ]; then
                cat "refs/$ref"
            elif [ -f "revs/$ref/.commit.systr" ]; then
                echo "$ref"
            else
                echo "$ref is not a revision" >&2
                exit 1
            fi
        )
    fi
}

##
# systrunk log [<commit>=BASE]
#
# View commit history.  Generate a dump of all commits reachable
# from the given commit, or BASE if no argument is given.
##
function systr_log
{
    if [ $# -lt 1 ]; then
        commit="$BASE"
    else
        commit=$(systr_repo_resolve_reference "$1")
    fi

    while [[ "$commit" != "NULL" ]]
    do
        (
            cd "$path/revs/$commit/"

            read date <.date.systr
            read author <.author.systr
            read email <.email.systr

            printf '%s %s\n'     "$commit" "$date"
            printf '%s <%s>\n\n' "$author" "$email"
            cat .mesg.systr
            echo ""
            echo ""
        )

        read commit <"$path/revs/$commit/.commit.systr"
    done
}

##
# systrunk init <name>
#
# Initialize a repository called "<name>.systr" in the current
# directory.
##
function systr_init
{
    if [ $# -lt 1 ]; then
        echo "Fatal: too few args to init" >&2
        exit 1
    fi

    name="$1"

    mkdir "$name.systr"
    cd "$name.systr"

    mkdir refs revs
    echo "NULL" >refs/HEAD
}