Changeset 3796 for trunk/LMDZ.COMMON


Ignore:
Timestamp:
Jun 5, 2025, 4:14:08 PM (3 days ago)
Author:
jbclement
Message:

COMMON:
Avoid redundant git diff calls in subdirectories for "version_diff.txt" when a top-level repository is detected.
JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/makelmdz_fcm

    r3665 r3796  
    599599########################################################################
    600600
     601# Path to the root directory where we want to check version control system
     602root_dir="$LMDGCM/.."
     603
    601604# Path and name of the generated file
    602605info_file="$LIBFGCM/misc/version_info.F90"
     
    609612
    610613# Function to process problematic characters
    611 #     Convert input to UTF-8 and ignore invalid characters
    612 #     Remove carriage return characters to prevent formatting issues
    613 #     Escape backslashes and single quotes
     614#   - Convert input to UTF-8 and ignore invalid characters
     615#   - Remove carriage return characters to prevent formatting issues
     616#   - Escape backslashes and single quotes
    614617clean_output() {
    615618    iconv -f "$(locale charmap)" -t UTF-8//IGNORE \
     
    618621}
    619622
    620 # Iterate through subdirectories in $LMDGCM/../ to determine version control system
    621623vcs_info=""
    622624vcs_diff=""
    623625vcs_stat=""
    624 for dir in "$LMDGCM/.."/*; do
    625     # Skip if it is not a directory or the name contains "git" or "svn"
    626     [ -d "$dir" ] || continue
    627     [[ "$dir" == *git* || "$dir" == *svn* ]] && continue
    628 
    629     # Determine the version control system for each subdirectory
    630     if command -v svn > /dev/null && svn info "$dir" > /dev/null 2>&1; then # SVN
    631         vcs_info+="\n-> SVN Information for \"$(basename "$dir")\"\n$(svn info "$dir" | clean_output)\n"
    632         vcs_diff+="\n-> SVN Diff for \"$(basename "$dir")\"\n$(svn diff "$dir" | clean_output)\n"
    633         vcs_stat+="\n-> SVN Status for \"$(basename "$dir")\"\n$(svn status "$dir" | clean_output)\n"
    634     elif command -v git > /dev/null && git -C "$dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then # Git
    635         vcs_info+="-> Git Information for \"$(basename "$dir")\"\n$(git -C "$dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s" | clean_output)\n"
    636         vcs_diff+="\n-> Git Diff for \"$(basename "$dir")\"\n$(git -C "$dir" diff | clean_output)\n"
    637         vcs_stat+="\n-> Git Status for \"$(basename "$dir")\"\n$(git -C "$dir" status --short | clean_output)\n"
    638     else # None
    639         vcs_info+="\n-> No version control system for \"$(basename "$dir")\"\n"
    640     fi
    641 done
     626# Check if there is a Git repository at the root
     627if command -v git > /dev/null 2>&1 && git -C "$root_dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then
     628    dir_name="$(basename "$root_dir")"
     629    vcs_info+="-> Git Information for \"$dir_name\"\n$(git -C "$root_dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s" | clean_output)\n"
     630    vcs_stat+="-> Git Status for \"$dir_name\"\n$(git -C "$root_dir" status --short | clean_output)\n"
     631    vcs_diff+="-> Git Diff for \"$dir_name\"\n$(git -C "$root_dir" diff | clean_output)\n"
     632else # No so we iterate through each subdirectory to determine version control system
     633    for dir in "$root_dir"/*; do
     634        # Skip if it is not a directory or the name contains "git" or "svn"
     635        [ -d "$dir" ] || continue
     636        [[ "$dir" == *git* || "$dir" == *svn* ]] && continue
     637
     638        # Determine the version control system for each subdirectory
     639        dir_name="$(basename "$dir")"
     640        if command -v svn > /dev/null 2>&1 && svn info "$dir" > /dev/null 2>&1; then # SVN
     641            vcs_info+="\n-> SVN Information for \"$dir_name\"\n$(svn info "$dir" | clean_output)\n"
     642            vcs_diff+="\n-> SVN Diff for \"$dir_name\"\n$(svn diff "$dir" | clean_output)\n"
     643            vcs_stat+="\n-> SVN Status for \"$dir_name\"\n$(svn status "$dir" | clean_output)\n"
     644        elif command -v git > /dev/null 2>&1 && git -C "$dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then # Git
     645            vcs_info+="-> Git Information for \"$dir_name\"\n$(git -C "$dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s" | clean_output)\n"
     646            vcs_diff+="\n-> Git Diff for \"$dir_name\"\n$(git -C "$dir" diff | clean_output)\n"
     647            vcs_stat+="\n-> Git Status for \"$dir_name\"\n$(git -C "$dir" status --short | clean_output)\n"
     648        else # None
     649            vcs_info+="\n-> No version control system for \"$dir_name\"\n"
     650        fi
     651    done
     652fi
    642653
    643654# Generate the Fortran subroutine
Note: See TracChangeset for help on using the changeset viewer.