Ignore:
Timestamp:
Jan 14, 2025, 4:05:38 PM (3 weeks ago)
Author:
jbclement
Message:

COMMON:
Follow-up of r3574:

  • Small corrections to make it work with Git;
  • Addition of the functionality with the programs 'Generic newstart' and 'Generic start2archive';
  • Improvements of the visualization format;
  • Diplaying version control information of every sub-folder in the "trunk" instead of only the "trunk" (who can do more can do less).

JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/makelmdz_fcm

    r3574 r3576  
    608608current_date=$(date)
    609609
    610 # Determine version control system (SVN, Git or none)
    611 if command -v svn > /dev/null && svn info > /dev/null 2>&1; then
    612     vcs="svn"
    613     vcs_info=$(svn info $LMDGCM/..)
    614     vcs_diff=$(svn diff $LMDGCM/..)
    615 elif command -v git > /dev/null && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
    616     vcs="git"
    617     vcs_info=$(git log -1 --pretty=format:"%H%n%an%n%ad%n%s" $LMDGCM/..)
    618     vcs_diff=$(git diff $LMDGCM/..)
    619 else
    620     vcs="none"
    621 fi
    622 
    623 # Function to escape the simple quotation sign
    624 escape_signs() {
    625     echo "$1" | sed "s/'/''/g"
    626 }
     610# Iterate through subdirectories in $LMDGCM/../ to determine version control system
     611vcs_info=""
     612vcs_diff=""
     613for dir in "$LMDGCM/.."/*; do
     614    # Skip if it is not a directory or the name contains "git" or "svn"
     615    [ -d "$dir" ] || continue
     616    [[ "$dir" == *git* || "$dir" == *svn* ]] && continue
     617
     618    # Determine the version control system for each subdirectory
     619    if command -v svn > /dev/null && svn info "$dir" > /dev/null 2>&1; then # SVN
     620        vcs_info+="\n=== SVN Information for $dir ===\n$(svn info "$dir")\n"
     621        vcs_diff+="\n=== SVN Diff for $dir ===\n$(svn diff "$dir")\n"
     622    elif command -v git > /dev/null && git -C "$dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then # Git
     623        vcs_info+="\n=== Git Information for $dir ===\n$(git -C "$dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s")\n"
     624        vcs_diff+="\n=== Git Diff for $dir ===\n$(git -C "$dir" diff)\n"
     625    else # None
     626        vcs_info+="\n=== No version control system for $dir ===\n"
     627    fi
     628done
    627629
    628630# Generate the Fortran subroutine
     
    653655SUBROUTINE print_version_info()
    654656
    655     write(*,*) '=== Compilation details ==='
    656     write(*,*) 'Date: ${current_date}'
    657     write(*,*) 'Command: ${compilation_command}'
     657    write(*,'(A)') '======= Compilation details ======='
     658    write(*,'(A)') 'Date: ${current_date}'
     659    write(*,'(A)') 'Command: ${compilation_command}'
    658660    write(*,*)
    659661EOF
    660662
    661 if [ "$vcs" == "svn" ]; then # SVN info
    662     echo "    write(*,*) '===== SVN Information ====='" >> "$info_file"
     663if [ -n "$vcs_info" ]; then
     664    echo "    write(*,'(A)') '=== Version Control Information ==='" >> "$info_file"
    663665    while IFS= read -r line; do
    664         echo "    write(*,*) '${line//\"/\\\"}'" >> "$info_file"
    665     done <<< "$vcs_info"
     666        echo "    write(*,'(A)') '${line//\'/\'\'}'" >> "$info_file"
     667    done <<< "$(echo -e "$vcs_info")"
     668fi
     669
     670if [ -n "$vcs_diff" ]; then
    666671    echo "    write(*,*)" >> "$info_file"
    667     echo "    write(*,*) '======== SVN Diff ========='" >> "$info_file"
    668     echo "    write(*,*) 'Writing SVN diff to file: ${diff_file}'" >> "$info_file"
    669     echo "    open(unit = 1,file = \"${diff_file}\",status = 'replace')" >> "$info_file"
     672    echo "    write(*,'(A)') '====== Version Control Diff ======='" >> "$info_file"
     673    echo "    write(*,'(A)') 'Writing diff to file: ${diff_file}'" >> "$info_file"
     674    echo "    open(unit = 1, file = \"${diff_file}\", status = 'replace', action = 'write')" >> "$info_file"
    670675    while IFS= read -r line; do
    671         escaped_line=$(escape_signs "$line")
    672         echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
    673     done <<< "$vcs_diff"
     676        echo "    write(1,'(A)') '${line//\'/\'\'}'" >> "$info_file"
     677    done <<< "$(echo -e "$vcs_diff")"
    674678    echo "    close(1)" >> "$info_file"
    675 
    676 
    677 elif [ "$vcs" == "git" ]; then # Git info
    678     echo "    write(*,*) '===== Git Information ====='" >> "$info_file"
    679     while IFS= read -r line; do
    680         echo "    write(*,*) \"${line//\"/\\\"}\"" >> "$info_file"
    681     done <<< "$vcs_info"
    682     echo "    write(*,*)" >> "$info_file"
    683     echo "    write(*,*) '======== Git Diff ========='" >> "$info_file"
    684     echo "    write(*,*) 'Writing Git diff to file: ${diff_file}'" >> "$info_file"
    685     while IFS= read -r line; do
    686         escaped_line=$(escape_signs "$line")
    687         echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
    688     done <<< "$vcs_diff"
    689     echo "    close(1)" >> "$info_file"
    690 else # Non-versioned code
    691     echo "    write(*,*) 'No version control information available.'" >> "$info_file"
    692 fi
    693     echo "    write(*,*) '==========================='" >> "$info_file"
     679fi
    694680
    695681cat << EOF >> "$info_file"
     682    write(*,'(A)') '==================================='
    696683
    697684END SUBROUTINE print_version_info
Note: See TracChangeset for help on using the changeset viewer.