├── .gitignore ├── misc ├── .gitignore ├── benchmark ├── git-restore-mtime-min └── cprofile ├── windows ├── .gitignore ├── build_windows_executable.bat ├── non-ascii-paths.txt └── README.md ├── .gitattributes ├── .editorconfig ├── man1 ├── TODO.md ├── git-find-uncommitted-repos.1 ├── git-branches-rename.1 ├── git-rebase-theirs.1 ├── git-strip-merge.1 ├── git-clone-subset.1 └── git-restore-mtime.1 ├── git-find-uncommitted-repos ├── git-branches-rename ├── git-rebase-theirs ├── git-strip-merge ├── git-clone-subset ├── README.md ├── git-restore-mtime └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | git_restore_mtime.py 2 | -------------------------------------------------------------------------------- /misc/.gitignore: -------------------------------------------------------------------------------- 1 | data/ 2 | git-utimes 3 | timing* 4 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /dist 3 | /git-restore-mtime.spec 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize EOL for all files that Git considers text files 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | # Use TAB for shell files 8 | [*] 9 | end_of_line = lf 10 | insert_final_newline = true 11 | charset = utf-8 12 | indent_style = tab 13 | indent_size = 8 14 | 15 | # 4 space indentation for python files 16 | [{git-restore-mtime, *.py}] 17 | indent_style = space 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /man1/TODO.md: -------------------------------------------------------------------------------- 1 | # Manual pages TO-DO 2 | 3 | - Write man pages source files in _Markdown_ and use `pandoc` to convert to _groff_: 4 | 5 | ``` 6 | for doc in *.1.md; do 7 | pandoc --standalone --target man --output "${doc%.md}" -- "$doc" 8 | fi 9 | ``` 10 | 11 | ## Testing 12 | ``` 13 | pandoc --standalone --target man -- git-restore-mtime.1.md | man -l - 14 | man -l git-restore-mtime.1 15 | manpath # default search path for manpages 16 | ``` 17 | 18 | ## References 19 | * https://www.howtogeek.com/682871/how-to-create-a-man-page-on-linux/ 20 | 21 | ## Also worth considering 22 | - help2man 23 | - http://www.gnu.org/software/help2man 24 | - `sudo apt install help2man` 25 | - txt2man 26 | - https://github.com/mvertes/txt2man 27 | - `sudo apt install txt2man` 28 | - ronn 29 | - https://github.com/rtomayko/ronn 30 | - `sudo apt install ruby-ronn` 31 | -------------------------------------------------------------------------------- /man1/git-find-uncommitted-repos.1: -------------------------------------------------------------------------------- 1 | .TH GIT-FIND-UNCOMMITTED-REPOS 1 2016-01-31 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-find-uncommitted-repos \- 8 | Recursively list repositories with uncommitted changes 9 | .SH SYNOPSIS 10 | .B git-find-uncommitted-repos 11 | .RI [ DIR ...] 12 | .SH DESCRIPTION 13 | Recursively list repositories with uncommitted changes. 14 | .SH OPTIONS 15 | .TP 8 16 | .BR \-h , \ \-\-help 17 | show usage information. 18 | .TP 8 19 | .BR \-v , \ \-\-verbose 20 | print more details about what is being done. 21 | .TP 8 22 | .BR \-u , \ \-\-untracked 23 | count untracked files as 'uncommitted' 24 | .TP 8 25 | .IR DIR ... 26 | the directories to scan, or current directory if none is specified. 27 | .SH SEE ALSO 28 | .B https://github.com/MestreLion/git-tools 29 | .SH AUTHOR 30 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 31 | -------------------------------------------------------------------------------- /man1/git-branches-rename.1: -------------------------------------------------------------------------------- 1 | .TH GIT-BRANCHES-RENAME 1 2016-01-31 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-branches-rename \- 8 | Batch renames branches with a matching prefix to another prefix 9 | .SH SYNOPSIS 10 | .B git-branches-rename 11 | .RI [ options ] 12 | .I BRANCH_PREFIX NEW_PREFIX 13 | .SH DESCRIPTION 14 | Batch renames branches with a matching prefix to another prefix. 15 | .SH OPTIONS 16 | .TP 8 17 | .BR \-h , \ \-\-help 18 | show usage information. 19 | .TP 8 20 | .BR \-v , \ \-\-verbose 21 | print more details about what is being done. 22 | .TP 8 23 | .BR \-n , \ \-\-dry-run 24 | do not actually rename the branches. 25 | .TP 8 26 | .I BRANCH_PREFIX 27 | a prefix that matches the start of branch names. 28 | .TP 8 29 | .I NEW_PREFIX 30 | the new prefix for the branch names. 31 | .SH EXAMPLES 32 | .nf 33 | $ git-rename-branches bug bugfix 34 | bug/128 -> bugfix/128 35 | bug_test -> bugfix_test 36 | 37 | $ git-rename-branches ma backup/ma 38 | master -> backup/master 39 | main -> backup/main 40 | .fi 41 | .SH SEE ALSO 42 | .B https://github.com/MestreLion/git-tools 43 | .SH AUTHOR 44 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 45 | -------------------------------------------------------------------------------- /misc/benchmark: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # benchmark - benchmarking git-restore-mtime 4 | # 5 | # This file is part of git-tools, see 6 | # Copyright (C) 2022 Rodrigo Silva (MestreLion) 7 | # License: GPLv3 or later, at your choice. See 8 | #------------------------------------------------------------------------------ 9 | 10 | here="${0%/*}" 11 | case "${1:-}" in 12 | touch) cmd=( touch-all );; 13 | min) cmd=( "$here"/git-restore-mtime-min );; 14 | utimes) cmd=( "$here"/git-utimes );; 15 | *) cmd=( "$here"/../git-restore-mtime "$@" );; 16 | esac 17 | 18 | # flush() could be more complete: https://stackoverflow.com/a/44266604/624066 19 | flush() { sync; echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null; } 20 | touch-all() { i=0; while IFS= read -r file; do ((i++)); touch "$file"; 21 | done < <(git ls-files); echo "$i files"; } 22 | 23 | # touch variations, only works if [[ $(find . -name '* *' | wc -l) == 0 ]] 24 | touch-for() ( i=0; for file in $(git ls-files); do ((i++)); touch "$file"; 25 | done; echo "$i files"; ) 26 | touch-min() ( for file in $(git ls-files); do touch "$file"; done; ) 27 | 28 | touch-all 29 | git status >/dev/null 2>&1 # for the linux kernel 30 | flush 31 | time { "${cmd[@]}"; } 32 | -------------------------------------------------------------------------------- /misc/git-restore-mtime-min: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # Original post from https://stackoverflow.com/a/13284229/624066 3 | # 4 | # Bare-bones version. Current directory must be top-level of work tree. 5 | # Usage: git-restore-mtime-bare [pathspecs...] 6 | # By default update all files 7 | # Example: to only update only the README and files in ./doc: 8 | # git-restore-mtime-bare README doc 9 | 10 | import subprocess, shlex 11 | import sys, os.path 12 | 13 | filelist = set() 14 | for path in (sys.argv[1:] or [os.path.curdir]): 15 | if os.path.isfile(path) or os.path.islink(path): 16 | filelist.add(os.path.relpath(path)) 17 | elif os.path.isdir(path): 18 | for root, subdirs, files in os.walk(path): 19 | if '.git' in subdirs: 20 | subdirs.remove('.git') 21 | for file in files: 22 | filelist.add(os.path.relpath(os.path.join(root, file))) 23 | 24 | mtime = 0 25 | gitobj = subprocess.Popen(shlex.split('git log --raw --no-show-signature --pretty=%at'), 26 | stdout=subprocess.PIPE) 27 | for line in gitobj.stdout: 28 | line = line.strip() 29 | if not line: continue 30 | 31 | if line.startswith(':'): 32 | file = line.split('\t')[-1] 33 | if file in filelist: 34 | filelist.remove(file) 35 | #print mtime, file 36 | os.utime(file, (mtime, mtime)) 37 | else: 38 | mtime = long(line) 39 | 40 | # All files done? 41 | if not filelist: 42 | break 43 | -------------------------------------------------------------------------------- /man1/git-rebase-theirs.1: -------------------------------------------------------------------------------- 1 | .TH GIT-REBASE-THEIRS 1 2016-01-31 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-rebase-theirs \- 8 | Resolve rebase conflicts and failed cherry-picks by favoring 'theirs' version 9 | .SH SYNOPSIS 10 | .B git-rebase-theirs 11 | .RI [ options ] 12 | .RI [ -- ] 13 | .IR FILE ... 14 | .SH DESCRIPTION 15 | Resolve git rebase conflicts in FILE(s) by favoring 'theirs' version. 16 | 17 | When using git rebase, conflicts are usually wanted to be resolved by favoring 18 | the version (the branch being rebased, 'theirs' side in a 19 | rebase), instead of the version (the base branch, 'ours' side) 20 | 21 | But git rebase --strategy -X theirs is only available from git 1.7.3 22 | For older versions, git-rebase-theirs is the solution. And Despite the name, 23 | it's also useful for fixing failed cherry-picks. 24 | 25 | It works by discarding all lines between '<<<<<<< ' and '========' 26 | inclusive, and also the the '>>>>>> commit' marker. 27 | 28 | By default it outputs to stdout, but files can be edited in-place 29 | using --in-place, which, unlike sed, creates a backup by default. 30 | .SH OPTIONS 31 | .TP 8 32 | .BR \-h , \ \-\-help 33 | show usage information. 34 | .TP 8 35 | .BR \-v , \ \-\-verbose 36 | print more details in stderr. 37 | .TP 8 38 | .BI \-\-in-place [=SUFFIX] 39 | edit files in place, creating a backup with 40 | .I SUFFIX 41 | extension. Default if blank is ".bak" 42 | .TP 8 43 | .B \-\-no-backup 44 | disables backup 45 | .SH SEE ALSO 46 | .B https://github.com/MestreLion/git-tools 47 | .SH AUTHOR 48 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 49 | -------------------------------------------------------------------------------- /windows/build_windows_executable.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | IF "%1"=="/INIT" GOTO InitializeEnvironment 3 | PUSHD "%~dp0" 4 | 5 | ECHO. 6 | ECHO Checking current python.exe location(s) 7 | where python.exe 8 | 9 | ECHO. 10 | ECHO Version info for Python/pip/pyinstaller: 11 | python.exe --version 12 | pip.exe --version 13 | pyinstaller.exe --version 14 | 15 | ECHO. 16 | ECHO Testing if current git-restore-mtime Python script works... 17 | python.exe ..\git-restore-mtime --help 18 | 19 | REM pyinstaller uses upx by default to compress the executable 20 | REM When running the created executable this results in an error: 21 | REM git-restore-mtime.exe - Bad Image: %TEMP%\VCRUNTIME140.dll 22 | REM is either not designed to run on Windows or it contains an error (..) 23 | REM Therefore run pyinstaller with the --noupx parameter 24 | pyinstaller.exe -F --noupx ..\git-restore-mtime 25 | 26 | ECHO. 27 | ECHO Testing if git-restore-mtime.exe works... 28 | dist\git-restore-mtime.exe --help 29 | 30 | PAUSE 31 | GOTO :EOF 32 | 33 | :InitializeEnvironment 34 | ECHO. 35 | ECHO NOTE: This script needs to run as administrator 36 | ECHO Press a key to install Chocolatey, Python and the required Python packages... 37 | PAUSE 38 | 39 | ECHO. 40 | ECHO Installing/updating Chocolatey... 41 | @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass ^ 42 | -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" ^ 43 | && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 44 | 45 | ECHO. 46 | ECHO Installing/updating Python... 47 | choco.exe install -y python 48 | 49 | ECHO. 50 | ECHO Upgrading pip and setuptools to latest version... 51 | pip.exe install --upgrade --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools 52 | 53 | ECHO. 54 | ECHO Installing latest version of pyinstaller... 55 | pip.exe install --trusted-host pypi.org --trusted-host files.pythonhosted.org ^ 56 | https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz 57 | 58 | ECHO. 59 | ECHO Finished! 60 | PAUSE 61 | GOTO :EOF 62 | -------------------------------------------------------------------------------- /man1/git-strip-merge.1: -------------------------------------------------------------------------------- 1 | .TH GIT-STRIP-MERGE 1 2016-01-31 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-strip-merge \- 8 | A git-merge wrapper that deletes files on a "foreign" branch before merging 9 | .SH SYNOPSIS 10 | .B git-strip-merge 11 | .RI [ git-merge\ options ] 12 | .RB [ -M 13 | .IR ] 14 | .I 15 | .IR FILE ... 16 | .SH DESCRIPTION 17 | git-merge that deletes files on "foreign" before merging. 18 | .sp 19 | Useful for ignoring a folder in before merging it with 20 | current branch. Works by deleting FILE(S) in a detached commit based 21 | on , and then performing the merge of this new commit in the 22 | current branch. Note that is not changed by this procedure. 23 | Also note that may actually be any reference, like a tag, 24 | or a remote branch, or even a commit SHA. 25 | .sp 26 | For more information, see 27 | .SH OPTIONS 28 | .TP 8 29 | .BR \-h , \ \-\-help 30 | show help message and exit 31 | .TP 8 32 | .BR \-v , \ \-\-verbose 33 | do not use -q to suppress normal output of internal steps from git 34 | checkout, rm, commit. By default, only git merge output is shown. 35 | Errors, however, are never suppressed. 36 | .TP 8 37 | .BR \-M\ , \ \-\-msgcommit = 38 | message for the removal commit in . Not to be confused 39 | with the message of the merge commit, which is set by -m. Default 40 | message is: "remove files from '' before merge". 41 | .TP 8 42 | .BR \-m\ , \ \-\-message = 43 | message for the merge commit. Since we are not merging 44 | directly, but rather a detached commit based on it, we forge a 45 | message similar to git's default for a branch merge. Otherwise 46 | git would use in message the full and ugly SHA1 of our commit. 47 | Default message is: "Merge stripped branch ''". 48 | .PP 49 | For both commit messages, the token "" is replaced for the 50 | actual name. 51 | .sp 52 | Additional options are passed unchecked to git merge. 53 | .sp 54 | All options must precede and FILE(s), except -h and --help 55 | that may appear anywhere on the command line. 56 | .SH EXAMPLE 57 | .nf 58 | git-strip-merge design "photoshop/*" 59 | .fi 60 | .SH SEE ALSO 61 | .B https://github.com/MestreLion/git-tools 62 | .SH AUTHOR 63 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 64 | -------------------------------------------------------------------------------- /git-find-uncommitted-repos: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # git-find-uncommitted-repos - recursively list repos with uncommitted changes 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. See 19 | # 20 | # Recursively finds all git repositories in each PATH argument, runs git status 21 | # on them, and prints the location of repositories with uncommitted changes 22 | # Only works for conventional repositories where git dir is "/.git" 23 | 24 | myname="${0##*/}" 25 | untracked=no 26 | 27 | invalid() { printf "%s: invalid option: %s\n" "$myname" "$1" >&2 ; usage 1 ; } 28 | usage() { 29 | cat <<-USAGE 30 | Usage: $myname [-u] [DIR...] 31 | USAGE 32 | if [[ "$1" ]] ; then 33 | cat >&2 <<- USAGE 34 | Try '$myname --help' for more information. 35 | USAGE 36 | exit 1 37 | fi 38 | cat <<-USAGE 39 | 40 | Recursively list repositories with uncommitted changes 41 | 42 | Options: 43 | -h|--help - show this page. 44 | -u|--untracked - count untracked files as 'uncommitted' 45 | 46 | DIR... - the directories to scan, or current directory if none 47 | is specified. 48 | 49 | Copyright (C) 2012 Rodrigo Silva (MestreLion) 50 | License: GPLv3 or later. See 51 | USAGE 52 | exit 0 53 | } 54 | 55 | # Option handling 56 | dirs=() 57 | for arg in "$@"; do [[ "$arg" == "-h" || "$arg" == "--help" ]] && usage ; done 58 | while (( $# )); do 59 | case "$1" in 60 | -u|--untracked) untracked=normal ;; 61 | -- ) shift ; break ;; 62 | -* ) invalid "$1" ;; 63 | * ) dirs+=( "$1" ) ;; 64 | esac 65 | shift 66 | done 67 | dirs+=( "$@" ) 68 | 69 | while read -r repo; do 70 | repo="$(dirname "$repo")" 71 | uncommitted=$(cd "$repo" && git status --short --untracked-files="$untracked") 72 | if [[ "$uncommitted" ]]; then echo "$repo"; fi 73 | done < <(find "${dirs[@]}" -name .git -type d) 74 | -------------------------------------------------------------------------------- /misc/cprofile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # cprofile - profiling git-restore-mtime 4 | # 5 | # This file is part of git-tools, see 6 | # Copyright (C) 2022 Rodrigo Silva (MestreLion) 7 | # License: GPLv3 or later, at your choice. See 8 | #------------------------------------------------------------------------------ 9 | 10 | myself="${0##*/}" 11 | here="${0%/*}" 12 | 13 | #------------------------------------------------------------------------------ 14 | now() { date +%Y%m%d%H%M%S; } 15 | exists() { type "$@" >/dev/null 2>&1; } 16 | command-latest() { 17 | local prefix=$1 18 | compgen -c "$prefix" | 19 | grep -P "^${prefix}\d[.\d]*\$" | 20 | sort -ruV | 21 | head -n1 22 | } 23 | pip-install() { 24 | local packages=( "$@" ) 25 | local pip; pip=$(command-latest pip) 26 | local python; python=${python:-$(command-latest python)} 27 | if exists "${packages[@]}"; then return; fi 28 | if exists pipx; then 29 | pipx install -- "${packages[@]}" 30 | return 31 | fi 32 | if ! exists "$pip"; then 33 | sudo apt install python3-pip 34 | fi 35 | "$python" -m pip install --user "${packages[@]}" 36 | } 37 | #------------------------------------------------------------------------------ 38 | 39 | outdir=${here}/data 40 | repo=${PWD##*/} 41 | pstats=${outdir}/${repo}.$(now).pstats 42 | python=$(command-latest python) 43 | 44 | #------------------------------------------------------------------------------ 45 | usage() { 46 | cat <<- USAGE 47 | Usage: $myself [options] 48 | USAGE 49 | if [[ "$1" ]] ; then 50 | cat <<- USAGE 51 | Try '$myself --help' for more information. 52 | USAGE 53 | exit 1 54 | fi 55 | cat <<-USAGE 56 | 57 | Profiling git-restore-mtime. Run from a repository root 58 | 59 | Options: 60 | -h|--help - show this page. 61 | 62 | Copyright (C) 2022 Rodrigo Silva (MestreLion) 63 | License: GPLv3 or later. See 64 | USAGE 65 | exit 0 66 | } 67 | invalid() { echo "$myself: invalid option $1" ; usage 1 ; } 68 | missing() { echo "$myself: missing ${1:+$1 }operand" ; usage 1 ; } 69 | 70 | # Loop options 71 | while (( $# )); do 72 | case "$1" in 73 | -h|--help ) usage;; 74 | -P|--python ) shift; python=${1:-};; 75 | --python=* ) python=${1#*=};; 76 | -- ) shift ; break;; 77 | -* ) invalid "$1" ; break;; 78 | * ) break;; 79 | esac 80 | shift 81 | done 82 | 83 | [[ "$python" ]] || missing --python 84 | if ! exists "$python"; then "$python"; usage 1; fi 85 | 86 | #------------------------------------------------------------------------------ 87 | pip-install gprof2dot 88 | 89 | mkdir -p -- "$outdir" 90 | "$python" -m cProfile -o "$pstats" "$here"/../git-restore-mtime 91 | gprof2dot -f pstats -o "$pstats".dot -- "$pstats" 92 | xdg-open "$pstats".dot 93 | -------------------------------------------------------------------------------- /git-branches-rename: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # git-rename-branches - rename multiple branches that start with a given name 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see 19 | 20 | usage() { 21 | cat <<- USAGE 22 | Usage: $self [options] BRANCH_PREFIX NEW_PREFIX 23 | USAGE 24 | if [[ "$1" ]] ; then 25 | cat <<- USAGE 26 | Try '$self --help' for more information. 27 | USAGE 28 | exit 1 29 | fi 30 | cat <<-USAGE 31 | 32 | Batch renames branches with a matching prefix to another prefix 33 | 34 | Options: 35 | -h|--help - show this page. 36 | -v|--verbose - print more details about what is being done. 37 | -n|--dry-run - do not actually renames the branches. 38 | 39 | BRANCH_PREFIX - a prefix that matches the start of branch names 40 | NEW_PREFIX - the new prefix for the branch names 41 | 42 | Examples: 43 | $ git-rename-branches bug bugfix 44 | bug/128 -> bugfix/128 45 | bug_test -> bugfix_test 46 | 47 | $ git-rename-branches ma backup/ma 48 | master -> backup/master 49 | main -> backup/main 50 | 51 | Copyright (C) 2012 Rodrigo Silva (MestreLion) 52 | License: GPLv3 or later. See 53 | USAGE 54 | exit 0 55 | } 56 | invalid() { echo "$self: invalid option $1" ; usage 1 ; } 57 | missing() { echo "$self: missing ${1:+$1 }operand" ; usage 1 ; } 58 | 59 | self="${0##*/}" 60 | verbose=0 61 | dry_run=0 62 | 63 | # Loop options 64 | while (( $# )); do 65 | case "$1" in 66 | -h|--help ) usage ;; 67 | -v|--verbose ) verbose=1 ;; 68 | -n|--dry-run ) dry_run=1 ;; 69 | -- ) shift ; break ;; 70 | -* ) invalid "$1" ; break ;; 71 | * ) break ;; 72 | esac 73 | shift 74 | done 75 | 76 | [[ "$1" && "$2" ]] || missing 'a PREFIX' 77 | 78 | while read -r branch; do 79 | if ((dry_run)) ; then 80 | ((verbose)) && echo "$branch -> ${2}${branch#$1}" 81 | else 82 | git branch -m "$branch" "${2}${branch#$1}" && 83 | ((verbose)) && echo "$branch -> ${2}${branch#$1}" 84 | fi 85 | done < <(git branch | awk -v branches="${1/\\/\\\\}" '$NF ~ "^" branches {print $NF}') 86 | -------------------------------------------------------------------------------- /windows/non-ascii-paths.txt: -------------------------------------------------------------------------------- 1 | For git-restore-mtime to work, path name encoding used by Git and Python must agree, 2 | and that might depend on the underlying filesystem encoding. So: 3 | 4 | - If filesystem encoding is UTF-8 normalization form C, it's all good. All hail Linux! 5 | 6 | - On Mac, HFS+ uses UTF-8, but not normalization form C, so letters with accents 7 | might use 2 Unicode code-points. Does Git properly deals with this? No idea. 8 | https://developer.apple.com/library/archive/technotes/tn/tn1150.html#UnicodeSubtleties 9 | https://stackoverflow.com/a/9758019/624066 10 | 11 | - On Windows, native NTFS encoding *might* be UTF-16 or something else, and Git 12 | (on Windows) might or might not transcode that to UTF-8 norm C when storing. 13 | Git doc is not conclusive enough, depending on how you interpret this: 14 | https://github.com/git/git/blob/master/Documentation/i18n.txt 15 | 16 | Git is to some extent character encoding agnostic. 17 | - Path names are encoded in UTF-8 normalization form C. This 18 | applies to tree objects, the index file, ref names, as well as 19 | path names in command line arguments, environment variables 20 | and config files. 21 | + 22 | Note that Git at the core level treats path names simply as 23 | sequences of non-NUL bytes, there are no path name encoding 24 | conversions (except on Mac and Windows). Therefore, using 25 | non-ASCII path names will mostly work even on platforms and file 26 | systems that use legacy extended ASCII encodings. However, 27 | repositories created on such systems will not work properly on 28 | UTF-8-based systems (e.g. Linux, Mac, Windows) and vice versa. 29 | Additionally, many Git-based tools simply assume path names to 30 | be UTF-8 and will fail to display other encodings correctly. 31 | 32 | - Also worth reading: https://github.com/git-for-windows/git/wiki/FAQ, specially 33 | "Some native console programs don't work when run from Git Bash. How to fix it?" 34 | and https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support 35 | 36 | - Terminal might play a role. Git for Windows apparently uses `minitty`, check 37 | if (and how) it performs transcoding. Same for PowerShell, if applicable. 38 | 39 | - Setting `git config core.quotepath off` might fix issues. 40 | On Mac, `core.precomposeunicode` may play a role. 41 | 42 | 43 | - Using `-z` in `ls-files` and `whatchanged` is an option to consider. 44 | For reading NUL-delimited data, see https://stackoverflow.com/q/9237246/624066 45 | 46 | Bottom line, the following encodings must all agree with each other: 47 | - Git ls-files / whatchanged ASCII escaping when core.quotepath on (the default) 48 | - Git ls-files / whatchanged binary output when core.quotepath off 49 | - Python `Popen.stdout` decoding when using `universal_newlines=True`/`text=True`, 50 | (or specified `encoding`) if quotepath off 51 | - normalize() un-escape algorithm if quotepath on. It currently assumes UTF-8 escaping 52 | - paths in args.{pathspec,gitdir,workdir,...} 53 | - path parameter for os.utime(), os.path.dirname() (if args.pathspec) 54 | -------------------------------------------------------------------------------- /man1/git-clone-subset.1: -------------------------------------------------------------------------------- 1 | .TH GIT-CLONE-SUBSET 1 2021-02-11 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-clone-subset \- 8 | Clones a subset of a git repository 9 | .SH SYNOPSIS 10 | .B git-clone-subset 11 | .RI [ options ] 12 | .I repository destination-dir pattern 13 | .SH DESCRIPTION 14 | Clones a 15 | .I repository 16 | into a 17 | .I destination-dir 18 | and prune from history all files except the ones matching 19 | .I pattern 20 | by running on the clone: 21 | .br 22 | .B git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all 23 | .br 24 | This effectively creates a clone with a subset of files (and history) 25 | of the original repository. The original repository is not modified. 26 | .sp 27 | Useful for creating a new repository out of a set of files from another 28 | repository, migrating (only) their associated history. Very similar to: 29 | .br 30 | .B git filter-branch --subdirectory-filter 31 | .br 32 | But git-clone-subset works on a path pattern instead of just a single directory. 33 | .SH OPTIONS 34 | .TP 8 35 | .BR \-h , \ \-\-help 36 | show usage information. 37 | .TP 8 38 | .I repository 39 | URL or local path to the git repository to be cloned. 40 | .TP 8 41 | .I destination-dir 42 | Directory to create the clone. Same rules for git-clone applies: it 43 | will be created if it does not exist and it must be empty otherwise. 44 | But, unlike git-clone, this argument is not optional: git-clone uses 45 | several rules to determine the "friendly" basename of a cloned repo, 46 | and git-clone-subset will not risk parse its output, let alone 47 | predict the chosen name. 48 | .TP 8 49 | .I pattern 50 | Glob pattern to match the desired files/dirs. It will be ultimately 51 | evaluated by a call to bash, NOT git or sh, using extended 52 | glob '!()' rule. Quote it or escape it on command line, so it 53 | does not get evaluated prematurely by your current shell. Only a 54 | single pattern is allowed: if more are required, use extglob's "|" 55 | syntax. Globs will be evaluated with bash's shopt dotglob set, so 56 | beware. Patterns should not contain spaces or special chars 57 | like " ' $ ( ) { } `, not even quoted or escaped, since that might 58 | interfere with the !() syntax after pattern expansion. 59 | .sp 60 | Pattern Examples: 61 | .sp 62 | "*.png" 63 | .br 64 | "*.png|*icon*" 65 | .br 66 | "*.h|src/|lib" 67 | .SH LIMITATIONS 68 | Renames are NOT followed. As a workaround, list the rename history 69 | with 'git log --follow --name-status --format='%H' -- file | grep "^[RAD]"' 70 | and include all multiple names of a file in the pattern, as 71 | in "current_name|old_name|initial_name". As a side effect, if a different 72 | file has taken place of an old name, it will be preserved too, and 73 | there is no way around this using this tool. 74 | .sp 75 | There is no (easy) way to keep some files in a dir: using 'dir/foo*' 76 | as pattern will not work. So keep the whole dir and remove files 77 | afterwards, using git filter-branch and a (quite complex) combination 78 | of cloning, remote add, rebase, etc. 79 | .sp 80 | Pattern matching is quite limited, and many of bash's escaping and 81 | quoting does not work properly when pattern is expanded inside !(). 82 | .SH SEE ALSO 83 | .B https://github.com/MestreLion/git-tools 84 | .SH AUTHOR 85 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 86 | -------------------------------------------------------------------------------- /windows/README.md: -------------------------------------------------------------------------------- 1 | Tools to build a stand-alone Windows executable 2 | =============================================== 3 | 4 | Windows batch files to build a stand-alone Windows executable 5 | that can be distributed without the need to install Python. 6 | At this time the batch file only builds an executable for 7 | git-restore-mtime: `git-restore-mtime.exe`. 8 | 9 | 10 | Requirements 11 | ------------ 12 | 13 | - **Windows**. Tested with Windows 8.1 14 | - **Git**. Tested in v2.17.1 and prior versions since 2010 15 | - **Python**. Requires at least Python 3.8.0 16 | - **pip**. Tested with pip 19.3.1 17 | - **setuptools**. Tested with setuptools 42.0.0 18 | - **pyinstaller**. Tested with pyinstaller 4.0.dev0+1eadfa55f2 19 | 20 | Automatic installation of requirements 21 | ----------------------------------- 22 | You can automatically perform the installation of all requirements 23 | by running the following command from an elevated command prompt: 24 | ```cmd 25 | build_windows_executable.bat /INIT 26 | ``` 27 | 28 | Manual installation of requirements 29 | ----------------------------------- 30 | The easiest way to install Git and Python on Windows is with Chocolatey (https://chocolatey.org). 31 | 32 | NOTE: The easiest way to run the installation commands below is with 'Run as administrator'. 33 | For pip.exe you could use a '--user' parameter to bypass this, 34 | but then you have to add the specific user directory to the PATH to make everything work. 35 | 36 | Installing Chocolatey (): 37 | ```cmd 38 | @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass ^ 39 | -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" ^ 40 | && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 41 | ``` 42 | 43 | Installing the latest Git and Python with Chocolatey: 44 | ```cmd 45 | choco.exe install Git 46 | choco.exe install Python 47 | ``` 48 | Upgrading pip and setuptools to the latest version: 49 | ```cmd 50 | pip.exe install --upgrade --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools 51 | ``` 52 | Installing the latest version of pyinstaller: 53 | ```cmd 54 | pip.exe install --trusted-host pypi.org --trusted-host files.pythonhosted.org ^ 55 | https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz 56 | ``` 57 | Creating the Windows Executable 58 | If all dependencies are met, all you have to do is doubleclick (or run from a non-elevated command prompt): 59 | ``` 60 | build_windows_executable.bat 61 | ``` 62 | This should result in a 'dist\git-restore-mtime.exe' file. 63 | 64 | All other files that are created are temporary files: 65 | Both 'git-restore-mtime.spec' and the 'build/' directory can be discarded. 66 | 67 | --- 68 | 69 | Note on Anti-Virus scan reports 70 | ------------------------------- 71 | 72 | Some Anti Virus tools such as TotalVirus may report the generated `git-restore-mtime.exe` as containing malware. 73 | 74 | **This is a false positive**, and a known issue with all software built using `pyinstaller`. 75 | The rationale and a possible workaround is best described in this [pyinstaller's issue](https://github.com/pyinstaller/pyinstaller/issues/6754): 76 | 77 | > The only way you can avoid getting false positives is to sign your executable, which requires paying for a certificate. 78 | > The false positives occur because some people use PyInstaller for malware, and PyInstaller's bootloader is the only guaranteed common piece between them all. 79 | -------------------------------------------------------------------------------- /git-rebase-theirs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # git-rebase-theirs - Resolve rebase conflicts by favoring 'theirs' version 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not see 19 | 20 | #Defaults: 21 | verbose=0 22 | backup=1 23 | inplace=0 24 | ext=".bak" 25 | 26 | message() { printf "%s\n" "$1" >&2 ; } 27 | argerr() { printf "%s: %s\n" "$myname" "${1:-error}" >&2 ; usage 1 ; } 28 | invalid() { argerr "invalid option: $1" ; } 29 | missing() { argerr "missing${1:+ $1} operand." ; } 30 | 31 | # Bash 4.4 does not allow 'continue' inside functions to operate on outer loops 32 | # See https://stackoverflow.com/a/52497694/624066 33 | skip() { message "skipping ${2:-$file}${1:+: $1}"; } 34 | 35 | usage() { 36 | cat <<- USAGE 37 | Usage: $myname [options] [--] FILE... 38 | USAGE 39 | if [[ "$1" ]] ; then 40 | cat >&2 <<- USAGE 41 | Try '$myname --help' for more information. 42 | USAGE 43 | exit 1 44 | fi 45 | cat <<-USAGE 46 | 47 | Resolve git rebase conflicts in FILE(s) by favoring 'theirs' version 48 | 49 | When using git rebase, one may want to automatically resolve conflicts 50 | by favoring the version, which is the branch being 51 | rebased, 'theirs' side in a rebase, instead of the version, 52 | the base branch, 'ours' side in the rebase. 53 | 54 | The solution is 'git rebase --strategy recursive -X theirs', which is 55 | only available since git 1.7.3. For older versions, $myname 56 | solves that problem. And despite its name it's also useful for fixing 57 | failed cherry-picks. 58 | 59 | It works by discarding all lines between '<<<<<<< ' and '========', 60 | inclusive, and also the '>>>>>> commit' marker. 61 | 62 | By default it outputs to stdout, but files can be edited in-place 63 | using --in-place, which, unlike sed, creates a backup by default. 64 | 65 | Options: 66 | -h|--help show this page. 67 | -v|--verbose print more details in stderr. 68 | 69 | --in-place[=SUFFIX] edit files in place, creating a backup with 70 | SUFFIX extension. Default if blank is "$ext" 71 | 72 | --no-backup disables backup 73 | 74 | Copyright (C) 2012 Rodrigo Silva (MestreLion) 75 | License: GPLv3 or later. See 76 | USAGE 77 | exit 0 78 | } 79 | myname="${0##*/}" 80 | 81 | # Option handling 82 | files=() 83 | while (( $# )); do 84 | case "$1" in 85 | -h|--help ) usage ;; 86 | -v|--verbose ) verbose=1 ;; 87 | --no-backup ) backup=0 ;; 88 | --in-place ) inplace=1 ;; 89 | --in-place=* ) inplace=1 90 | suffix="${1#*=}" ;; 91 | -- ) shift ; break ;; 92 | -* ) invalid "$1" ;; 93 | * ) files+=( "$1" ) ;; 94 | esac 95 | shift 96 | done 97 | files+=( "$@" ) 98 | 99 | if ! (( "${#files[@]}" )); then missing "FILE"; fi 100 | 101 | ext=${suffix:-$ext} 102 | 103 | for file in "${files[@]}"; do 104 | 105 | if ! [[ -f "$file" ]]; then skip "not a valid file"; continue; fi 106 | 107 | if ((inplace)); then 108 | outfile=$(mktemp) || 109 | { skip "could not create temporary file"; continue; } 110 | # shellcheck disable=SC2064 111 | trap "rm -f -- '$outfile'" EXIT 112 | cp "$file" "$outfile" || { skip; continue; } 113 | exec 3>"$outfile" 114 | else 115 | exec 3>&1 116 | fi 117 | 118 | # Do the magic :) 119 | awk '/^<<<<<<<+ .+$/,/^=+$/{next} /^>>>>>>>+ /{next} 1' "$file" >&3 120 | 121 | exec 3>&- 122 | 123 | if ! ((inplace)); then continue; fi 124 | 125 | diff "$file" "$outfile" >/dev/null && 126 | { skip "no conflict markers found"; continue; } 127 | 128 | if ((backup)); then 129 | cp "$file" "$file$ext" || { skip "could not backup"; continue; } 130 | fi 131 | 132 | cp "$outfile" "$file" || { skip "could not edit in-place"; continue; } 133 | rm -f -- "$outfile" 134 | trap - EXIT 135 | 136 | if ((verbose)); then message "resolved ${file}"; fi 137 | done 138 | -------------------------------------------------------------------------------- /git-strip-merge: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # git-strip-merge - a git-merge that delete files on branch before merging 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not see 19 | # 20 | # Answer for "How to setup a git driver to ignore a folder on merge?" 21 | # See http://stackoverflow.com/questions/3111515 22 | 23 | #Defaults: 24 | msgcommit="remove files from '' before merge" 25 | msgmerge="Merge stripped branch ''" 26 | verbose=0 27 | quiet=(--quiet) 28 | 29 | usage() { 30 | cat <<- USAGE 31 | Usage: $myname [git-merge options] [-M ] FILE... 32 | USAGE 33 | if [[ "$1" ]] ; then 34 | cat >&2 <<- USAGE 35 | Try '$myname --help' for more information. 36 | USAGE 37 | exit 1 38 | fi 39 | cat <<-USAGE 40 | 41 | git-merge that delete files on "foreign" before merging 42 | 43 | Useful for ignoring a folder in before merging it with 44 | current branch. Works by deleting FILE(S) in a detached commit based 45 | on , and then performing the merge of this new commit in the 46 | current branch. Note that is not changed by this procedure. 47 | Also note that may actually be any reference, like a tag, 48 | or a remote branch, or even a commit SHA. 49 | 50 | For more information, see 51 | 52 | Options: 53 | -h, --help 54 | show this page. 55 | 56 | -v, --verbose 57 | do not use -q to suppress normal output of internal steps from git 58 | checkout, rm, commit. By default, only git merge output is shown. 59 | Errors, however, are never suppressed 60 | 61 | -M , --msgcommit= 62 | message for the removal commit in . Not to be confused 63 | with the message of the merge commit, which is set by -m. Default 64 | message is: "$msgcommit" 65 | 66 | -m , --message= 67 | message for the merge commit. Since we are not merging 68 | directly, but rather a detached commit based on it, we forge a 69 | message similar to git's default for a branch merge. Otherwise 70 | git would use in message the full and ugly SHA1 of our commit. 71 | Default message is: "$msgmerge" 72 | 73 | For both commit messages, the token "" is replaced for the 74 | actual name. 75 | 76 | Additional options are passed unchecked to git merge. 77 | 78 | All options must precede and FILE(s), except -h and --help 79 | that may appear anywhere on the command line. 80 | 81 | Example: 82 | $myname design "photoshop/*" 83 | 84 | Copyright (C) 2012 Rodrigo Silva (MestreLion) 85 | License: GPLv3 or later. See 86 | USAGE 87 | exit 0 88 | } 89 | 90 | # Helper functions 91 | myname="${0##*/}" 92 | argerr() { printf "%s: %s\n" "${0##*/}" "${1:-error}" >&2 ; usage 1 ; } 93 | invalid() { argerr "invalid option: $1" ; } 94 | missing() { argerr "missing ${2:+$2 }operand${1:+ from $1}." ; } 95 | 96 | # Option handling 97 | files=() 98 | mergeopts=() 99 | for arg in "$@"; do case "$arg" in -h|--help) usage ;; esac; done 100 | while (( $# )); do 101 | case "$1" in 102 | -v|--verbose ) verbose=1 ;; 103 | -M ) shift ; msgcommit=$1 ;; 104 | -m ) shift ; msgmerge=$1 ;; 105 | --msgcommit=* ) msgcommit=${1#*=} ;; 106 | --message=* ) msgmerge=${1#*=} ;; 107 | -* ) mergeopts+=( "$1" ) ;; 108 | * ) branch="$1" 109 | shift ; break ;; 110 | esac 111 | shift 112 | done 113 | files+=( "$@" ) 114 | 115 | # Argument handling 116 | 117 | msgcommit=${msgcommit///$branch} 118 | msgmerge=${msgmerge///$branch} 119 | 120 | [[ "$msgcommit" ]] || missing "msgcommit" "MSG" 121 | [[ "$branch" ]] || missing "" "" 122 | (( ${#files[@]} )) || missing "" "FILE" 123 | 124 | ((verbose)) && quiet=() 125 | 126 | # Here the fun begins... 127 | gitsha() { git rev-parse "$1" ; } 128 | gitbranch() { 129 | git symbolic-ref "$1" 2> /dev/null | sed 's/refs\/heads\///' || 130 | gitsha "$1" 131 | } 132 | 133 | original=$(gitbranch HEAD) 134 | branchsha=$(gitsha "$branch") 135 | 136 | trap 'git checkout --quiet "$original"' EXIT 137 | 138 | git checkout "$branchsha" "${quiet[@]}" && 139 | git rm -rf "${files[@]}" "${quiet[@]}" && 140 | git commit -m "$msgcommit" "${quiet[@]}" && 141 | newsha=$(gitsha HEAD) && 142 | git checkout "$original" "${quiet[@]}" && 143 | git merge -m "$msgmerge" "${mergeopts[@]}" "$newsha" 144 | -------------------------------------------------------------------------------- /man1/git-restore-mtime.1: -------------------------------------------------------------------------------- 1 | .TH GIT-RESTORE-MTIME 1 2022-07-27 2 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 3 | .\" way too many mistakes in technical documents. 4 | .if n .ad l 5 | .nh 6 | .SH NAME 7 | git-restore-mtime \- 8 | Restore original modification time of files based on the date of the most 9 | recent commit that modified them 10 | .SH SYNOPSIS 11 | .TP 18 12 | .B git-restore-mtime 13 | .RB [ -h ] 14 | .RB [ --quiet | --verbose ] 15 | .br 16 | .RB [ -C 17 | .IR DIRECTORY ] 18 | .RB [ --work-tree 19 | .IR WORKDIR ] 20 | .RB [ --git-dir 21 | .IR GITDIR ] 22 | .br 23 | .RB [ --force ] 24 | .RB [ --merge ] 25 | .RB [ --first-parent ] 26 | .RB [ --skip-missing ] 27 | .br 28 | .RB [ --no-directories ] 29 | .RB [ --test ] 30 | .RB [ --commit-time ] 31 | .RB [ --oldest-time ] 32 | .br 33 | .RB [ --skip-older-than 34 | .IR SECONDS ] 35 | .RB [ --unique-times ] 36 | .RB [ --version ] 37 | .br 38 | .RI [ PATHSPEC 39 | .RI [ PATHSPEC ...]] 40 | .SH DESCRIPTION 41 | Change the modification time (mtime) of files in the work tree based on the 42 | date of the most recent commit that modified the file, as an attempt to 43 | restore the original modification time. Useful when generating release tarballs. 44 | 45 | Ignore untracked files and uncommitted deletions, additions and renames, and 46 | by default modifications too. 47 | .SH OPTIONS 48 | .SS Positional arguments: 49 | .TP 8 50 | .I PATHSPEC 51 | Only modify paths matching \fIPATHSPEC\fR, relative to current directory. 52 | By default, update all but untracked files and submodules. 53 | .SS Optional arguments: 54 | .TP 8 55 | .BR \-h ,\ \-\-help 56 | show help message and exit 57 | .TP 8 58 | .BR \-\-quiet , \-q 59 | Suppress informative messages and summary statistics. 60 | .TP 8 61 | .BR \-\-verbose , \-v 62 | Print additional information for each processed file. 63 | Specify twice to further increase verbosity. 64 | .TP 8 65 | .BI \-C\ DIRECTORY\fR,\ \-\-cwd\ DIRECTORY 66 | Run as if \fBrestore-mtime\fR was started in directory \fIDIRECTORY\fR. 67 | This affects how \fB--work-tree\fR, \fB--git-dir\fR and \fIPATHSPEC\fR arguments 68 | are handled. 69 | See \fBgit\fR(1) for more information. 70 | .TP 8 71 | .BI \-\-git-dir\ GITDIR 72 | Path to the git repository, by default auto-discovered by searching 73 | the current directory and its parents for a \fI.git/\fR subdirectory. 74 | .TP 8 75 | .BI \-\-work-tree\ WORKDIR 76 | Path to the work tree root, by default the parent of \fIGITDIR\fR if it's 77 | automatically discovered, or the current directory if \fIGITDIR\fR is set. 78 | .TP 8 79 | .BR \-\-force ,\ \-f 80 | Force updating files with uncommitted modifications. 81 | Untracked files and uncommitted deletions, renames and additions are 82 | always ignored. 83 | .TP 8 84 | .BR \-\-merge ,\ \-m 85 | Include merge commits. 86 | Leads to more recent times and more files per commit, thus with the same 87 | time, which may or may not be what you want. 88 | Including merge commits may lead to fewer commits being evaluated as files 89 | are found sooner, which can improve performance, sometimes substantially. 90 | But as merge commits are usually huge, processing them may also take longer. 91 | By default, merge commits are only used for files missing from regular commits. 92 | .TP 8 93 | .BR \-\-first-parent 94 | Consider only the first parent, the "main branch", when evaluating merge commits. 95 | Only effective when merge commits are processed, either when \fB--merge\fR is 96 | used or when finding missing files after the first regular log search. 97 | See \fB--skip-missing\fR. 98 | .TP 8 99 | .BR \-\-skip-missing ,\ \-s 100 | Do not try to find missing files. 101 | If merge commits were not evaluated with \fB--merge\fR and some files were 102 | not found in regular commits, by default \fBrestore-mtime\fR searches for these 103 | files again in the merge commits. 104 | This option disables this retry, so files found only in merge commits 105 | will not have their timestamp updated. 106 | .TP 8 107 | .BR \-\-no-directories ,\ \-D 108 | Do not update directory timestamps. 109 | By default, use the time of its most recently created, renamed or deleted file. 110 | Note that just modifying a file will NOT update its directory time. 111 | .TP 8 112 | .BR \-\-test ,\ \-t 113 | Test run: do not actually update any file timestamp. 114 | .TP 8 115 | .BR \-\-commit-time ,\ \-c 116 | Use commit time instead of author time. 117 | .TP 8 118 | .BR \-\-oldest-time ,\ \-o 119 | Update times based on the oldest, instead of the most recent commit of a file. 120 | This reverses the order in which the git log is processed to emulate a 121 | file "creation" date. Note this will be inaccurate for files deleted and 122 | re-created at later dates. 123 | .TP 8 124 | .BI \-\-skip-older-than\ SECONDS 125 | Ignore files that are currently older than \fISECONDS\fR. 126 | Useful in workflows that assume such files already have a correct timestamp, 127 | as it may improve performance by processing fewer files. 128 | .TP 8 129 | .BR \-\-skip-older-than-commit ,\ \-N 130 | Ignore files older than the timestamp it would be updated to. 131 | Such files may be considered "original", likely in the author's repository. 132 | .TP 8 133 | .BR \-\-unique-times 134 | Set the microseconds to a unique value per commit. 135 | Allows telling apart changes that would otherwise have identical timestamps, 136 | as git's time accuracy is in seconds. 137 | .TP 8 138 | .BR \-\-version ,\ \-V 139 | show program's version number and exit 140 | .SH KNOWN ISSUES 141 | Renames are poorly handled: it always changes the timestamps 142 | of files, even if no content was modified. 143 | .br 144 | Directory timestamps are also limited to being modified 145 | only when files are added (created) or deleted in them. 146 | .br 147 | In very large repositories, after running \fBrestore-mtime\fR to modify 148 | the timestamp of several files, further git operations may emit the error: 149 | .br 150 | .B \ \ fatal: mmap failed: Cannot allocate memory. 151 | .br 152 | This is harmless, and can be fixed by running \fBgit-status\fR(1). 153 | .SH SEE ALSO 154 | .BR git (1),\ git-log (1),\ git-ls-files (1),\ git-status (1) 155 | .br 156 | .B https://github.com/MestreLion/git-tools 157 | .SH AUTHOR 158 | Rodrigo Silva (MestreLion) linux@rodrigosilva.com 159 | -------------------------------------------------------------------------------- /git-clone-subset: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # git-clone-subset - clones a subset of a git repository 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not see 19 | # 20 | # Uses git clone and git filter-branch to remove from the clone all files but 21 | # the ones requested, along with their associated commit history. 22 | 23 | usage() { 24 | cat <<- USAGE 25 | Usage: $myname [options] 26 | USAGE 27 | if [[ "$1" ]] ; then 28 | cat >&2 <<- USAGE 29 | Try '$myname --help' for more information. 30 | USAGE 31 | exit 1 32 | fi 33 | cat <<-USAGE 34 | 35 | Clones a into a and prune from history 36 | all files except the ones matching by running on the clone: 37 | git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all 38 | 39 | This effectively creates a clone with a subset of files (and history) 40 | of the original repository. The original repository is not modified. 41 | 42 | Useful for creating a new repository out of a set of files from another 43 | repository, migrating (only) their associated history. Very similar to: 44 | git filter-branch --subdirectory-filter 45 | But $myname works on a path pattern instead of just a single directory. 46 | 47 | Options: 48 | -h, --help 49 | show this page. 50 | 51 | 52 | URL or local path to the git repository to be cloned. 53 | 54 | 55 | Directory to create the clone. Same rules for git-clone applies: it 56 | will be created if it does not exist and it must be empty otherwise. 57 | But, unlike git-clone, this argument is not optional: git-clone uses 58 | several rules to determine the "friendly" basename of a cloned repo, 59 | and $myname will not risk parse its output, let alone 60 | predict the chosen name. 61 | 62 | 63 | Glob pattern to match the desired files/dirs. It will be ultimately 64 | evaluated by a call to bash, NOT git or sh, using extended glob 65 | '!()' rule. Quote it or escape it on command line, so it 66 | does not get evaluated prematurely by your current shell. Only a 67 | single pattern is allowed: if more are required, use extglob's "|" 68 | syntax. Globs will be evaluated with bash's shopt dotglob set, so 69 | beware. Patterns should not contain spaces or special chars like 70 | " ' \$ ( ) { } \`, not even quoted or escaped, since that might 71 | interfere with the !() syntax after pattern expansion. 72 | 73 | Pattern Examples: 74 | "*.png" 75 | "*.png|*icon*" 76 | "*.h|src/|lib" 77 | 78 | Limitations: 79 | 80 | - Renames are NOT followed. As a workaround, list the rename history with 81 | 'git log --follow --name-status --format='%H' -- file | grep "^[RAD]"' 82 | and include all multiple names of a file in the pattern, as in 83 | "current_name|old_name|initial_name". As a side effect, if a different 84 | file has taken place of an old name, it will be preserved too, and 85 | there is no way around this using this tool. 86 | 87 | - There is no (easy) way to keep some files in a dir: using 'dir/foo*' 88 | as pattern will not work. So keep the whole dir and remove files 89 | afterwards, using git filter-branch and a (quite complex) combination 90 | of cloning, remote add, rebase, etc. 91 | 92 | - Pattern matching is quite limited, and many of bash's escaping and 93 | quoting does not work properly when pattern is expanded inside !(). 94 | 95 | Copyright (C) 2013 Rodrigo Silva (MestreLion) 96 | License: GPLv3 or later. See 97 | USAGE 98 | exit 0 99 | } 100 | 101 | # Helper functions 102 | myname="${0##*/}" 103 | argerr() { printf "%s: %s\n" "${0##*/}" "${1:-error}" >&2 ; usage 1 ; } 104 | invalid() { argerr "invalid option: $1" ; } 105 | missing() { argerr "missing ${2:+$2 }operand${1:+ from $1}." ; } 106 | 107 | # Argument handling 108 | for arg in "$@"; do case "$arg" in -h|--help) usage ;; esac; done 109 | 110 | repo=$1 111 | dir=$2 112 | pattern=$3 113 | 114 | [[ "$repo" ]] || missing "" "" 115 | [[ "$dir" ]] || missing "" "" 116 | [[ "$pattern" ]] || missing "" "" 117 | 118 | (($# > 3)) && argerr "too many arguments: $4" 119 | 120 | # Clone the repo and enter it 121 | git clone --no-hardlinks "$repo" "$dir" && cd "$dir" && 122 | 123 | # Remove remotes (a clone is meant to be a different repository) 124 | while read -r remote; do 125 | git remote rm "$remote" || break 126 | done < <(git remote) && 127 | 128 | # The heart of the script 129 | git filter-branch --prune-empty --tree-filter \ 130 | "bash -O dotglob -O extglob -c 'git rm -rf --ignore-unmatch -- !($pattern)'" \ 131 | -- --all && 132 | 133 | # fix a bug in filter-branch where empty root commits are not removed 134 | # even with --prune-empty. First we loop each root commit 135 | while read -r root; do 136 | 137 | # Test if it's an non-empty commit 138 | if [[ "$(git ls-tree "$root")" ]]; then continue; fi 139 | 140 | # Now "remove" it by deleting its child's parent reference 141 | git filter-branch --force --parent-filter "sed 's/-p $root//'" -- --all 142 | 143 | done < <(git rev-list --max-parents=0 HEAD) && 144 | 145 | # Delete backups and the reflog, not needed in a clone 146 | if [[ -e .git/refs/original/ ]] ; then 147 | git "for-each-ref" --format="%(refname)" refs/original/ | 148 | xargs -n 1 git update-ref -d 149 | fi && 150 | git reflog expire --expire=now --all && 151 | git gc --prune=now 152 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Git Tools 2 | ========= 3 | 4 | Assorted git-related scripts and tools 5 | 6 | 7 | Requirements 8 | ------------ 9 | 10 | - **Git** (duh!). Tested in v2.17.1 and prior versions since 2010 11 | - **Python** (for `git-restore-mtime`). Requires Python 3.8 or later 12 | - **Bash** (for all other tools). Tested in Bash 4, some may work in Bash 3 or even `sh` 13 | 14 | Bash and Python are already installed by default in virtually all GNU/Linux distros. 15 | And you probably already have Git if you are interested in these tools. 16 | If needed, the command to install dependencies for Debian-like distros (like Ubuntu/Mint) is: 17 | 18 | sudo apt install bash python3 git 19 | 20 | Installation 21 | ------------ 22 | 23 | For [Debian](https://tracker.debian.org/pkg/git-mestrelion-tools), 24 | [Ubuntu](https://launchpad.net/ubuntu/+source/git-mestrelion-tools), 25 | LinuxMint, and their derivatives, in official repositories as `git-restore-mtime`: 26 | 27 | sudo apt install git-restore-mtime 28 | 29 | For [Fedora](https://src.fedoraproject.org/rpms/git-tools) 30 | and in EPEL repository for CentOS, Red Hat Enterprise Linux (RHEL), Oracle Linux and others, as root: 31 | 32 | dnf install git-tools # 'yum' if using older CentOS/RHEL releases 33 | 34 | [Gentoo](https://packages.gentoo.org/packages/dev-vcs/git-tools) and Funtoo, also as root: 35 | 36 | emerge dev-vcs/git-tools 37 | 38 | Arch Linux [AUR](https://aur.archlinux.org/packages/git-tools-git): 39 | 40 | Follow the [AUR instructions](https://wiki.archlinux.org/title/Arch_User_Repository#Installing_and_upgrading_packages) to build and install a package from the user contributed PKGBUILD or use your favorite AUR helper. Note this is a recipie for a VCS package that installs the latest Git HEAD as of the time you build the package, not the latest stable taggged version. 41 | 42 | [Homebrew](https://formulae.brew.sh/formula/git-tools): 43 | 44 | brew install git-tools 45 | 46 | [MacPorts](https://ports.macports.org/port/git-tools/details/): 47 | 48 | sudo port install git-tools 49 | 50 | Also available in Kali Linux, MidnightBDS _mports_, Mageia, and possibly other distributions. 51 | 52 | [GitHub Actions](https://github.com/marketplace/actions/git-restore-mtime): _(`git-restore-mtime` only)_ 53 | ```yaml 54 | build: 55 | steps: 56 | - uses: actions/checkout@v3 57 | with: 58 | fetch-depth: 0 59 | - uses: chetan/git-restore-mtime-action@v2 60 | ``` 61 | 62 | **Manual install**: to run from the repository tree, just clone and add the installation directory to your `$PATH`: 63 | ```sh 64 | cd ~/some/dir 65 | git clone https://github.com/MestreLion/git-tools.git 66 | echo 'PATH=$PATH:~/some/dir/git-tools' >> ~/.profile # or ~/.bashrc 67 | ``` 68 | 69 | To install the `man` pages, simply copy (or symlink) the files from [`man1/`](man1) folder 70 | to `~/.local/share/man/man1`, creating the directory if necessary: 71 | ```sh 72 | dest=${XDG_DATA_HOME:$HOME/.local/share}/man/man1 73 | mkdir -p -- "$dest" 74 | cp -t "$dest" -- ~/some/dir/git-tools/man1/*.1 # or `ln -s -t ...` 75 | ``` 76 | 77 | 78 | Usage 79 | ----- 80 | 81 | If you installed using your operating system package manager, or if you added the cloned repository to your `$PATH`, 82 | you can simply run the tools as if they were regular `git` subcommands! For example: 83 | 84 | git restore-mtime --test 85 | 86 | The magic? Git considers any executable named `git-*` in either `/usr/lib/git-core` or in `$PATH` to be a subcommand! 87 | It also integrates with `man`, triggering the manual pages if they're installed, 88 | such as when installing using your package manager: 89 | 90 | git restore-mtime --help 91 | git help strip-merge 92 | 93 | In case the manual pages are not installed in the system, such as when running from the cloned repository, 94 | you can still read the built-in help by directly invoking the tool: 95 | 96 | git-clone-subset --help 97 | 98 | 99 | Uninstall 100 | --------- 101 | 102 | For the packaged versions, use your repository tools such as `apt`, `brew`, `emerge`, or `yum`. 103 | 104 | For manual installations, delete the directory, manpages, and remove it from your `$PATH`. 105 | ```sh 106 | rm -rf ~/some/dir/git-tools # and optionally ~/.local/share/man/man1/git-*.1 107 | sed -i '/git-tools/d' ~/.profile 108 | ``` 109 | --- 110 | 111 | Tools 112 | ===== 113 | 114 | This is a brief description of the tools. For more detailed instructions, see `--help` of each tool. 115 | 116 | git-branches-rename 117 | ------------------- 118 | 119 | *Batch renames branches with a matching prefix to another prefix* 120 | 121 | Examples: 122 | 123 | ```console 124 | $ git-rename-branches bug bugfix 125 | bug/128 -> bugfix/128 126 | bug_test -> bugfix_test 127 | 128 | $ git-rename-branches ma backup/ma 129 | master -> backup/master 130 | main -> backup/main 131 | ``` 132 | 133 | git-clone-subset 134 | ---------------- 135 | 136 | *Clones a subset of a git repository* 137 | 138 | Uses `git clone` and `git filter-branch` to remove from the clone all but the requested files, 139 | along with their associated commit history. 140 | 141 | Clones a `repository` into a `destination` directory and runs 142 | `git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all` 143 | on the clone to prune from history all files except the ones matching a `pattern`, 144 | effectively creating a clone with a subset of files (and history) of the original repository. 145 | 146 | Useful for creating a new repository out of a set of files from another repository, 147 | migrating (only) their associated history. 148 | Very similar to what `git filter-branch --subdirectory-filter` does, 149 | but for a file pattern instead of just a single directory. 150 | 151 | 152 | git-find-uncommitted-repos 153 | -------------------------- 154 | 155 | *Recursively list repos with uncommitted changes* 156 | 157 | Recursively finds all git repositories in the given directory(es), runs `git status` on them, 158 | and prints the location of repositories with uncommitted changes. The tool I definitely use the most. 159 | 160 | 161 | git-rebase-theirs 162 | ----------------- 163 | 164 | *Resolve rebase conflicts and failed cherry-picks by favoring 'theirs' version* 165 | 166 | When using `git rebase`, conflicts are usually wanted to be resolved by favoring the `working branch` version 167 | (the branch being rebased, *'theirs'* side in a rebase), instead of the `upstream` version 168 | (the base branch, *'ours'* side). But `git rebase --strategy -X theirs` is only available from git 1.7.3. 169 | For older versions, `git-rebase-theirs` is the solution. 170 | Despite the name, it's also useful for fixing failed cherry-picks. 171 | 172 | 173 | git-restore-mtime 174 | ----------------- 175 | 176 | *Restore original modification time of files based on the date of the most recent commit that modified them* 177 | 178 | Probably the most popular and useful tool, and the reason this repository was packaged into distros. 179 | 180 | Git, unlike other version control systems, does not preserve the original timestamp of committed files. 181 | Whenever repositories are cloned, or branches/files are checked out, file timestamps are reset to the current date. 182 | While this behavior has its justifications (notably when using `make` to compile software), 183 | sometimes it is desirable to restore the original modification date of a file 184 | (for example, when generating release tarballs). 185 | As git does not provide any way to do that, `git-restore-mtime` tries to work around this limitation. 186 | 187 | For more information and background, see http://stackoverflow.com/a/13284229/624066 188 | 189 | For TravisCI users, simply add this setting to `.travis.yml` so it clones the full repository history: 190 | ```yaml 191 | git: 192 | depth: false 193 | ``` 194 | 195 | Similarly, when using GitHub Actions, make sure to include `fetch-depth: 0` in your checkout workflow, 196 | as described in its [documentation](https://github.com/actions/checkout#Fetch-all-history-for-all-tags-and-branches): 197 | ```yaml 198 | - uses: actions/checkout@v2 199 | with: 200 | fetch-depth: 0 201 | ``` 202 | 203 | 204 | git-strip-merge 205 | --------------- 206 | 207 | *A `git-merge` wrapper that delete files on a "foreign" branch before merging* 208 | 209 | Answer for "*How to set up a git driver to ignore a folder on merge?*", see http://stackoverflow.com/questions/3111515 210 | 211 | Example: 212 | ```console 213 | $ git checkout master 214 | $ git-strip-merge design photoshop/*.psd 215 | ``` 216 | --- 217 | 218 | Contributing 219 | ------------ 220 | 221 | Patches are welcome! Fork, hack, request pull! 222 | 223 | If you find a bug or have any enhancement request, please open a 224 | [new issue](https://github.com/MestreLion/git-tools/issues/new) 225 | 226 | 227 | Author 228 | ------ 229 | 230 | Rodrigo Silva (MestreLion) 231 | 232 | License and Copyright 233 | --------------------- 234 | ``` 235 | Copyright (C) 2012 Rodrigo Silva (MestreLion) . 236 | License GPLv3+: GNU GPL version 3 or later . 237 | This is free software: you are free to change and redistribute it. 238 | There is NO WARRANTY, to the extent permitted by law. 239 | ``` 240 | -------------------------------------------------------------------------------- /git-restore-mtime: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # git-restore-mtime - Change mtime of files based on commit date of last change 4 | # 5 | # Copyright (C) 2012 Rodrigo Silva (MestreLion) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. See 19 | # 20 | """ 21 | Change the modification time (mtime) of files in work tree, based on the 22 | date of the most recent commit that modified the file, including renames. 23 | 24 | Ignores untracked files and uncommitted deletions, additions and renames, and 25 | by default modifications too. 26 | --- 27 | Useful prior to generating release tarballs, so each file is archived with a 28 | date that is similar to the date when the file was actually last modified, 29 | assuming the actual modification date and its commit date are close. 30 | """ 31 | 32 | # TODO: 33 | # - Add -z on git log/ls-files, so we don't deal with filename decoding 34 | # - Update "Statistics for some large projects" with modern hardware and repositories. 35 | # - Create a README.md for git-restore-mtime alone. It deserves extensive documentation 36 | # - Move Statistics there 37 | # - See git-extras as a good example on project structure and documentation 38 | 39 | # FIXME: 40 | # - When current dir is outside the worktree, e.g. using --work-tree, `git ls-files` 41 | # assume any relative pathspecs are to worktree root, not the current dir. As such, 42 | # relative pathspecs may not work. 43 | # - Renames are tricky: 44 | # - R100 should not change mtime, but original name is not on filelist. Should 45 | # track renames until a valid (A, M) mtime found and then set on current name. 46 | # - Should set mtime for both current and original directories. 47 | # - Check mode changes with unchanged blobs? 48 | # - Check file (A, D) for the directory mtime is not sufficient: 49 | # - Renames also change dir mtime, unless rename was on a parent dir 50 | # - If most recent change of all files in a dir was a Modification (M), 51 | # dir might not be touched at all. 52 | # - Dirs containing only subdirectories but no direct files will also 53 | # not be touched. They're files' [grand]parent dir, but never their dirname(). 54 | # - Some solutions: 55 | # - After files done, perform some dir processing for missing dirs, finding latest 56 | # file (A, D, R) 57 | # - Simple approach: dir mtime is the most recent child (dir or file) mtime 58 | # - Use a virtual concept of "created at most at" to fill missing info, bubble up 59 | # to parents and grandparents 60 | # - When handling [grand]parent dirs, stay inside 61 | # - Better handling of merge commits. `-m` is plain *wrong*. `-c/--cc` is perfect, but 62 | # painfully slow. First pass without merge commits is not accurate. Maybe add a new 63 | # `--accurate` mode for `--cc`? 64 | 65 | if __name__ != "__main__": 66 | raise ImportError("{} should not be used as a module.".format(__name__)) 67 | 68 | import argparse 69 | import datetime 70 | import logging 71 | import os.path 72 | import shlex 73 | import signal 74 | import subprocess 75 | import sys 76 | import time 77 | 78 | if sys.version_info < (3, 8): 79 | sys.exit("Python 3.8 or later required.") 80 | 81 | __version__ = "2025.08" 82 | 83 | # Update symlinks only if the platform supports not following them 84 | UPDATE_SYMLINKS = bool({os.utime, os.stat} <= getattr(os, 'supports_follow_symlinks', set())) 85 | 86 | # Call os.path.normpath() only if not in a POSIX platform (Windows) 87 | NORMALIZE_PATHS = (os.path.sep != '/') 88 | 89 | # How many files to process in each batch when re-trying merge commits 90 | STEPMISSING = 100 91 | 92 | # (Extra) keywords for the os.utime() call performed by touch() 93 | UTIME_KWS = {} if not UPDATE_SYMLINKS else {'follow_symlinks': False} 94 | 95 | 96 | # Command-line interface ###################################################### 97 | 98 | def parse_args(): 99 | parser = argparse.ArgumentParser( 100 | description=__doc__.split('\n---')[0]) 101 | 102 | group = parser.add_mutually_exclusive_group() 103 | group.add_argument('--quiet', '-q', dest='loglevel', 104 | action="store_const", const=logging.WARNING, default=logging.INFO, 105 | help="Suppress informative messages and summary statistics.") 106 | group.add_argument('--verbose', '-v', action="count", help=""" 107 | Print additional information for each processed file. 108 | Specify twice to further increase verbosity. 109 | """) 110 | 111 | parser.add_argument('--cwd', '-C', metavar="DIRECTORY", help=""" 112 | Run as if %(prog)s was started in directory %(metavar)s. 113 | This affects how --work-tree, --git-dir and PATHSPEC arguments are handled. 114 | See 'man 1 git' or 'git --help' for more information. 115 | """) 116 | 117 | parser.add_argument('--git-dir', dest='gitdir', metavar="GITDIR", help=""" 118 | Path to the git repository, by default auto-discovered by searching 119 | the current directory and its parents for a .git/ subdirectory. 120 | """) 121 | 122 | parser.add_argument('--work-tree', dest='workdir', metavar="WORKTREE", help=""" 123 | Path to the work tree root, by default the parent of GITDIR if it's 124 | automatically discovered, or the current directory if GITDIR is set. 125 | """) 126 | 127 | parser.add_argument('--force', '-f', default=False, action="store_true", help=""" 128 | Force updating files with uncommitted modifications. 129 | Untracked files and uncommitted deletions, renames and additions are 130 | always ignored. 131 | """) 132 | 133 | parser.add_argument('--merge', '-m', default=False, action="store_true", help=""" 134 | Include merge commits. 135 | Leads to more recent times and more files per commit, thus with the same 136 | time, which may or may not be what you want. 137 | Including merge commits may lead to fewer commits being evaluated as files 138 | are found sooner, which can improve performance, sometimes substantially. 139 | But as merge commits are usually huge, processing them may also take longer. 140 | By default, merge commits are only used for files missing from regular commits. 141 | """) 142 | 143 | parser.add_argument('--first-parent', default=False, action="store_true", help=""" 144 | Consider only the first parent, the "main branch", when evaluating merge commits. 145 | Only effective when merge commits are processed, either when --merge is 146 | used or when finding missing files after the first regular log search. 147 | See --skip-missing. 148 | """) 149 | 150 | parser.add_argument('--skip-missing', '-s', dest="missing", default=True, 151 | action="store_false", help=""" 152 | Do not try to find missing files. 153 | If merge commits were not evaluated with --merge and some files were 154 | not found in regular commits, by default %(prog)s searches for these 155 | files again in the merge commits. 156 | This option disables this retry, so files found only in merge commits 157 | will not have their timestamp updated. 158 | """) 159 | 160 | parser.add_argument('--no-directories', '-D', dest='dirs', default=True, 161 | action="store_false", help=""" 162 | Do not update directory timestamps. 163 | By default, use the time of its most recently created, renamed or deleted file. 164 | Note that just modifying a file will NOT update its directory time. 165 | """) 166 | 167 | parser.add_argument('--test', '-t', default=False, action="store_true", 168 | help="Test run: do not actually update any file timestamp.") 169 | 170 | parser.add_argument('--commit-time', '-c', dest='commit_time', default=False, 171 | action='store_true', help="Use commit time instead of author time.") 172 | 173 | parser.add_argument('--oldest-time', '-o', dest='reverse_order', default=False, 174 | action='store_true', help=""" 175 | Update times based on the oldest, instead of the most recent commit of a file. 176 | This reverses the order in which the git log is processed to emulate a 177 | file "creation" date. Note this will be inaccurate for files deleted and 178 | re-created at later dates. 179 | """) 180 | 181 | parser.add_argument('--skip-older-than', metavar='SECONDS', type=int, help=""" 182 | Ignore files that are currently older than %(metavar)s. 183 | Useful in workflows that assume such files already have a correct timestamp, 184 | as it may improve performance by processing fewer files. 185 | """) 186 | 187 | parser.add_argument('--skip-older-than-commit', '-N', default=False, 188 | action='store_true', help=""" 189 | Ignore files older than the timestamp it would be updated to. 190 | Such files may be considered "original", likely in the author's repository. 191 | """) 192 | 193 | parser.add_argument('--unique-times', default=False, action="store_true", help=""" 194 | Set the microseconds to a unique value per commit. 195 | Allows telling apart changes that would otherwise have identical timestamps, 196 | as git's time accuracy is in seconds. 197 | """) 198 | 199 | parser.add_argument('pathspec', nargs='*', metavar='PATHSPEC', help=""" 200 | Only modify paths matching %(metavar)s, relative to current directory. 201 | By default, update all but untracked files and submodules. 202 | """) 203 | 204 | parser.add_argument('--version', '-V', action='version', 205 | version='%(prog)s version {version}'.format(version=get_version())) 206 | 207 | args_ = parser.parse_args() 208 | if args_.verbose: 209 | args_.loglevel = max(logging.TRACE, logging.DEBUG // args_.verbose) 210 | args_.debug = args_.loglevel <= logging.DEBUG 211 | return args_ 212 | 213 | 214 | def get_version(version=__version__): 215 | if not version.endswith('+dev'): 216 | return version 217 | try: 218 | cwd = os.path.dirname(os.path.realpath(__file__)) 219 | return Git(cwd=cwd, errors=False).describe().lstrip('v') 220 | except Git.Error: 221 | return '-'.join((version, "unknown")) 222 | 223 | 224 | # Helper functions ############################################################ 225 | 226 | def setup_logging(): 227 | """Add TRACE logging level and corresponding method, return the root logger""" 228 | logging.TRACE = TRACE = logging.DEBUG // 2 229 | logging.Logger.trace = lambda _, m, *a, **k: _.log(TRACE, m, *a, **k) 230 | return logging.getLogger() 231 | 232 | 233 | def normalize(path): 234 | r"""Normalize paths from git, handling non-ASCII characters. 235 | 236 | Git stores paths as UTF-8 normalization form C. 237 | If path contains non-ASCII or non-printable characters, git outputs the UTF-8 238 | in octal-escaped notation, escaping double-quotes and backslashes, and then 239 | double-quoting the whole path. 240 | https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath 241 | 242 | This function reverts this encoding, so: 243 | normalize(r'"Back\\slash_double\"quote_a\303\247a\303\255"') => 244 | r'Back\slash_double"quote_açaí') 245 | 246 | Paths with invalid UTF-8 encoding, such as single 0x80-0xFF bytes (e.g, from 247 | Latin1/Windows-1251 encoding) are decoded using surrogate escape, the same 248 | method used by Python for filesystem paths. So 0xE6 ("æ" in Latin1, r'\\346' 249 | from Git) is decoded as "\udce6". See https://peps.python.org/pep-0383/ and 250 | https://vstinner.github.io/painful-history-python-filesystem-encoding.html 251 | 252 | Also see notes on `windows/non-ascii-paths.txt` about path encodings on 253 | non-UTF-8 platforms and filesystems. 254 | """ 255 | if path and path[0] == '"': 256 | # Python 2: path = path[1:-1].decode("string-escape") 257 | # Python 3: https://stackoverflow.com/a/46650050/624066 258 | path = (path[1:-1] # Remove enclosing double quotes 259 | .encode('latin1') # Convert to bytes, required by 'unicode-escape' 260 | .decode('unicode-escape') # Perform the actual octal-escaping decode 261 | .encode('latin1') # 1:1 mapping to bytes, UTF-8 encoded 262 | .decode('utf8', 'surrogateescape')) # Decode from UTF-8 263 | if NORMALIZE_PATHS: 264 | # Make sure the slash matches the OS; for Windows we need a backslash 265 | path = os.path.normpath(path) 266 | return path 267 | 268 | 269 | def dummy(*_args, **_kwargs): 270 | """No-op function used in dry-run tests""" 271 | 272 | 273 | def touch(path, mtime): 274 | """The actual mtime update""" 275 | os.utime(path, (mtime, mtime), **UTIME_KWS) 276 | 277 | 278 | def touch_ns(path, mtime_ns): 279 | """The actual mtime update, using nanoseconds for unique timestamps""" 280 | os.utime(path, None, ns=(mtime_ns, mtime_ns), **UTIME_KWS) 281 | 282 | 283 | def isodate(secs: int): 284 | # time.localtime() accepts floats, but discards fractional part 285 | return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(secs)) 286 | 287 | 288 | def isodate_ns(ns: int): 289 | # for integers fromtimestamp() is equivalent and ~16% slower than isodate() 290 | return datetime.datetime.fromtimestamp(ns / 1000000000).isoformat(sep=' ') 291 | 292 | 293 | def get_mtime_ns(secs: int, idx: int): 294 | # Time resolution for filesystems and functions: 295 | # ext-4 and other POSIX filesystems: 1 nanosecond 296 | # NTFS (Windows default): 100 nanoseconds 297 | # datetime.datetime() (due to 64-bit float epoch): 1 microsecond 298 | us = idx % 1000000 # 10**6 299 | return 1000 * (1000000 * secs + us) 300 | 301 | 302 | def get_mtime_path(path): 303 | return os.stat(path, **UTIME_KWS).st_mtime 304 | 305 | 306 | # Git class and parse_log(), the heart of the script ########################## 307 | 308 | class Git: 309 | def __init__(self, workdir=None, gitdir=None, cwd=None, errors=True): 310 | self.gitcmd = ['git'] 311 | self.errors = errors 312 | self._proc = None 313 | if workdir: self.gitcmd.extend(('--work-tree', workdir)) 314 | if gitdir: self.gitcmd.extend(('--git-dir', gitdir)) 315 | if cwd: self.gitcmd.extend(('-C', cwd)) 316 | self.workdir, self.gitdir = self._get_repo_dirs() 317 | 318 | def ls_files(self, paths: list = None): 319 | return (normalize(_) for _ in self._run('ls-files --full-name', paths)) 320 | 321 | def ls_dirty(self, force=False): 322 | return (normalize(_[3:].split(' -> ', 1)[-1]) 323 | for _ in self._run('status --porcelain') 324 | if _[:2] != '??' and (not force or (_[0] in ('R', 'A') 325 | or _[1] == 'D'))) 326 | 327 | def log(self, merge=False, first_parent=False, commit_time=False, 328 | reverse_order=False, paths: list = None): 329 | cmd = 'log --raw --no-show-signature --pretty={}'.format('%ct' if commit_time else '%at') 330 | cmd += ' -m' if merge else ' --no-merges' 331 | if first_parent: cmd += ' --first-parent' 332 | if reverse_order: cmd += ' --reverse' 333 | return self._run(cmd, paths) 334 | 335 | def describe(self): 336 | return self._run('describe --tags', check=True)[0] 337 | 338 | def terminate(self): 339 | if self._proc is None: 340 | return 341 | try: 342 | self._proc.terminate() 343 | except OSError: 344 | # Avoid errors on OpenBSD 345 | pass 346 | 347 | def _get_repo_dirs(self): 348 | return (os.path.normpath(_) for _ in 349 | self._run('rev-parse --show-toplevel --absolute-git-dir', check=True)) 350 | 351 | def _run(self, cmdstr: str, paths: list = None, output=True, check=False): 352 | cmdlist = self.gitcmd + shlex.split(cmdstr) 353 | if paths: 354 | cmdlist.append('--') 355 | cmdlist.extend(paths) 356 | popen_args = dict(text=True, encoding='utf8') 357 | if not self.errors: 358 | popen_args['stderr'] = subprocess.DEVNULL 359 | log.trace("Executing: %s", ' '.join(cmdlist)) 360 | if not output: 361 | return subprocess.call(cmdlist, **popen_args) 362 | if check: 363 | try: 364 | stdout: str = subprocess.check_output(cmdlist, **popen_args) 365 | return stdout.splitlines() 366 | except subprocess.CalledProcessError as e: 367 | raise self.Error(e.returncode, e.cmd, e.output, e.stderr) 368 | self._proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, **popen_args) 369 | return (_.rstrip() for _ in self._proc.stdout) 370 | 371 | def __del__(self): 372 | self.terminate() 373 | 374 | class Error(subprocess.CalledProcessError): 375 | """Error from git executable""" 376 | 377 | 378 | def parse_log(filelist, dirlist, stats, git, merge=False, filterlist=None): 379 | mtime = 0 380 | datestr = isodate(0) 381 | for line in git.log( 382 | merge, 383 | args.first_parent, 384 | args.commit_time, 385 | args.reverse_order, 386 | filterlist 387 | ): 388 | stats['loglines'] += 1 389 | 390 | # Blank line between Date and list of files 391 | if not line: 392 | continue 393 | 394 | # Date line 395 | if line[0] != ':': # Faster than `not line.startswith(':')` 396 | stats['commits'] += 1 397 | mtime = int(line) 398 | if args.unique_times: 399 | mtime = get_mtime_ns(mtime, stats['commits']) 400 | if args.debug: 401 | datestr = isodate(mtime) 402 | continue 403 | 404 | # File line: three tokens if it describes a renaming, otherwise two 405 | tokens = line.split('\t') 406 | 407 | # Possible statuses: 408 | # M: Modified (content changed) 409 | # A: Added (created) 410 | # D: Deleted 411 | # T: Type changed: to/from regular file, symlinks, submodules 412 | # R099: Renamed (moved), with % of unchanged content. 100 = pure rename 413 | # Not possible in log: C=Copied, U=Unmerged, X=Unknown, B=pairing Broken 414 | status = tokens[0].split(' ')[-1] 415 | file = tokens[-1] 416 | 417 | # Handles non-ASCII chars and OS path separator 418 | file = normalize(file) 419 | 420 | def do_file(): 421 | if args.skip_older_than_commit and get_mtime_path(file) <= mtime: 422 | stats['skip'] += 1 423 | return 424 | if args.debug: 425 | log.debug("%d\t%d\t%d\t%s\t%s", 426 | stats['loglines'], stats['commits'], stats['files'], 427 | datestr, file) 428 | try: 429 | touch(os.path.join(git.workdir, file), mtime) 430 | stats['touches'] += 1 431 | except Exception as e: 432 | log.error("ERROR: %s: %s", e, file) 433 | stats['errors'] += 1 434 | 435 | def do_dir(): 436 | if args.debug: 437 | log.debug("%d\t%d\t-\t%s\t%s", 438 | stats['loglines'], stats['commits'], 439 | datestr, "{}/".format(dirname or '.')) 440 | try: 441 | touch(os.path.join(git.workdir, dirname), mtime) 442 | stats['dirtouches'] += 1 443 | except Exception as e: 444 | log.error("ERROR: %s: %s", e, dirname) 445 | stats['direrrors'] += 1 446 | 447 | if file in filelist: 448 | stats['files'] -= 1 449 | filelist.remove(file) 450 | do_file() 451 | 452 | if args.dirs and status in ('A', 'D'): 453 | dirname = os.path.dirname(file) 454 | if dirname in dirlist: 455 | dirlist.remove(dirname) 456 | do_dir() 457 | 458 | # All files done? 459 | if not stats['files']: 460 | git.terminate() 461 | return 462 | 463 | 464 | # Main Logic ################################################################## 465 | 466 | def main(): 467 | start = time.time() # yes, Wall time. CPU time is not realistic for users. 468 | stats = {_: 0 for _ in ('loglines', 'commits', 'touches', 'skip', 'errors', 469 | 'dirtouches', 'direrrors')} 470 | 471 | logging.basicConfig(level=args.loglevel, format='%(message)s') 472 | log.trace("Arguments: %s", args) 473 | 474 | # First things first: Where and Who are we? 475 | if args.cwd: 476 | log.debug("Changing directory: %s", args.cwd) 477 | try: 478 | os.chdir(args.cwd) 479 | except OSError as e: 480 | log.critical(e) 481 | return e.errno 482 | # Using both os.chdir() and `git -C` is redundant, but might prevent side effects 483 | # `git -C` alone could be enough if we make sure that: 484 | # - all paths, including args.pathspec, are processed by git: ls-files, rev-parse 485 | # - touch() / os.utime() path argument is always prepended with git.workdir 486 | try: 487 | git = Git(workdir=args.workdir, gitdir=args.gitdir, cwd=args.cwd) 488 | except Git.Error as e: 489 | # Not in a git repository, and git already informed user on stderr. So we just... 490 | return e.returncode 491 | 492 | # Get the files managed by git and build file list to be processed 493 | if UPDATE_SYMLINKS and not args.skip_older_than: 494 | filelist = set(git.ls_files(args.pathspec)) 495 | else: 496 | filelist = set() 497 | for path in git.ls_files(args.pathspec): 498 | fullpath = os.path.join(git.workdir, path) 499 | 500 | # Symlink (to file, to dir or broken - git handles the same way) 501 | if not UPDATE_SYMLINKS and os.path.islink(fullpath): 502 | log.warning("WARNING: Skipping symlink, no OS support for updates: %s", 503 | path) 504 | continue 505 | 506 | # skip files which are older than given threshold 507 | if (args.skip_older_than 508 | and start - get_mtime_path(fullpath) > args.skip_older_than): 509 | continue 510 | 511 | # Always add files relative to worktree root 512 | filelist.add(path) 513 | 514 | # If --force, silently ignore uncommitted deletions (not in the filesystem) 515 | # and renames / additions (will not be found in log anyway) 516 | if args.force: 517 | filelist -= set(git.ls_dirty(force=True)) 518 | # Otherwise, ignore any dirty files 519 | else: 520 | dirty = set(git.ls_dirty()) 521 | if dirty: 522 | log.warning("WARNING: Modified files in the working directory were ignored." 523 | "\nTo include such files, commit your changes or use --force.") 524 | filelist -= dirty 525 | 526 | # Build dir list to be processed 527 | dirlist = set(os.path.dirname(_) for _ in filelist) if args.dirs else set() 528 | 529 | stats['totalfiles'] = stats['files'] = len(filelist) 530 | log.info("{0:,} files to be processed in work dir".format(stats['totalfiles'])) 531 | 532 | if not filelist: 533 | # Nothing to do. Exit silently and without errors, just like git does 534 | return 535 | 536 | # Process the log until all files are 'touched' 537 | log.debug("Line #\tLog #\tF.Left\tModification Time\tFile Name") 538 | parse_log(filelist, dirlist, stats, git, args.merge, args.pathspec) 539 | 540 | # Missing files 541 | if filelist: 542 | # Try to find them in merge logs, if not done already 543 | # (usually HUGE, thus MUCH slower!) 544 | if args.missing and not args.merge: 545 | filterlist = list(filelist) 546 | missing = len(filterlist) 547 | log.info("{0:,} files not found in log, trying merge commits".format(missing)) 548 | for i in range(0, missing, STEPMISSING): 549 | parse_log(filelist, dirlist, stats, git, 550 | merge=True, filterlist=filterlist[i:i + STEPMISSING]) 551 | 552 | # Still missing some? 553 | for file in filelist: 554 | log.warning("WARNING: not found in the log: %s", file) 555 | 556 | # Final statistics 557 | # Suggestion: use git-log --before=mtime to brag about skipped log entries 558 | def log_info(msg, *a, width=13): 559 | ifmt = '{:%d,}' % (width,) # not using 'n' for consistency with ffmt 560 | ffmt = '{:%d,.2f}' % (width,) 561 | # %-formatting lacks a thousand separator, must pre-render with .format() 562 | log.info(msg.replace('%d', ifmt).replace('%f', ffmt).format(*a)) 563 | 564 | log_info( 565 | "Statistics:\n" 566 | "%f seconds\n" 567 | "%d log lines processed\n" 568 | "%d commits evaluated", 569 | time.time() - start, stats['loglines'], stats['commits']) 570 | 571 | if args.dirs: 572 | if stats['direrrors']: log_info("%d directory update errors", stats['direrrors']) 573 | log_info("%d directories updated", stats['dirtouches']) 574 | 575 | if stats['touches'] != stats['totalfiles']: 576 | log_info("%d files", stats['totalfiles']) 577 | if stats['skip']: log_info("%d files skipped", stats['skip']) 578 | if stats['files']: log_info("%d files missing", stats['files']) 579 | if stats['errors']: log_info("%d file update errors", stats['errors']) 580 | 581 | log_info("%d files updated", stats['touches']) 582 | 583 | if args.test: 584 | log.info("TEST RUN - No files modified!") 585 | 586 | 587 | # Keep only essential, global assignments here. Any other logic must be in main() 588 | log = setup_logging() 589 | args = parse_args() 590 | 591 | # Set the actual touch() and other functions based on command-line arguments 592 | if args.unique_times: 593 | touch = touch_ns 594 | isodate = isodate_ns 595 | 596 | # Make sure this is always set last to ensure --test behaves as intended 597 | if args.test: 598 | touch = dummy 599 | 600 | # UI done, it's showtime! 601 | try: 602 | sys.exit(main()) 603 | except KeyboardInterrupt: 604 | log.info("\nAborting") 605 | signal.signal(signal.SIGINT, signal.SIG_DFL) 606 | os.kill(os.getpid(), signal.SIGINT) 607 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------