Disable the localized output of utilities such as - ls, git, etc..
[midnight-commander.git] / src / vfs / extfs / helpers / changesetfs
blobeebdf8c7c331c16e3f3e5b7b3e2513d0930d217c
1 #!/bin/sh
3 LANG=C
4 export LANG
5 LC_TIME=C
6 export LC_TIME
8 # --- GIT -----------------------------------------------------------------------
10 found_git_dir()
12 work_dir=$1
13 while [ -n "$work_dir" -a "$work_dir" != "/" ]; do
14 [ -d "${work_dir}/.git" ] && {
15 echo "${work_dir}/.git/"
16 return
18 work_dir=`dirname "$work_dir"`
19 done
20 echo ''
23 changesetfs_list_git()
25 WORK_DIR=$1; shift
26 fname=$1; shift
27 USER=$1; shift
28 DATE=$1; shift
30 GIT_DIR=`found_git_dir "$WORK_DIR"`
31 [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR
32 curr_year=`date +"%Y"`
34 git --git-dir="$GIT_DIR" log --abbrev=7 --pretty="format:%at %h %an" -- "$fname" | while read TIMESTAMP chset author
36 year=`date -d @"$TIMESTAMP" +"%Y"`
37 [ "$year" = "$curr_year" ] && {
38 DATE=`date -d @"$TIMESTAMP" +"%b %d %H:%M"`
39 } || {
40 DATE=`date -d @"$TIMESTAMP" +"%b %d %Y"`
42 NAME="$chset $author"
43 echo "-rw-rw-rw- 1 $USER 0 0 $DATE $NAME `basename $fname`"
44 done
47 changesetfs_copyout_git()
49 WORK_DIR=$1; shift
50 fname=$1; shift
51 orig_fname=$1;shift
52 output_fname=$1;shift
54 chset=`echo "$orig_fname"| cut -f 1 -d " "`
56 GIT_DIR=`found_git_dir "$WORK_DIR"`
57 [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR
59 filecommit=`git --git-dir="$GIT_DIR" show --raw --pretty=tformat:%h "$chset" -- "$fname"| \
60 tail -n1 | \
61 sed 's@^::[0-9]*\s*[0-9]*\s*[0-9]*\s*@@' | \
62 sed 's@^:[0-9]*\s*[0-9]*\s*@@' | \
63 cut -d'.' -f 1`
64 git --git-dir="$GIT_DIR" show "$filecommit" > "$output_fname"
67 # --- COMMON --------------------------------------------------------------------
69 changesetfs_list()
71 VCS_type=$1; shift
72 WORK_DIR=$1; shift
73 fname=$1; shift
75 DATE=`date +"%b %d %H:%M"`
76 USER=`whoami`
78 case "$VCS_type" in
79 git) changesetfs_list_git "$WORK_DIR" "$fname" "$USER" "$DATE" ;;
80 esac
83 changesetfs_copyout()
85 VCS_type=$1; shift
86 WORK_DIR=$1; shift
87 fname=$1; shift
89 case "$VCS_type" in
90 git) changesetfs_copyout_git "$WORK_DIR" "$fname" "$@" ;;
91 esac
95 # --- MAIN ----------------------------------------------------------------------
97 command=$1; shift
98 tmp_file=$1; shift
100 WORK_DIR=`head -n1 $tmp_file`
101 fname=`tail -n2 $tmp_file | head -n1`
102 VCS_type=`tail -n1 $tmp_file`
104 case "$command" in
105 list) changesetfs_list "$VCS_type" "$WORK_DIR" "$fname" ;;
106 copyout) changesetfs_copyout "$VCS_type" "$WORK_DIR" "$fname" "$@" ;;
107 *) exit 1 ;;
108 esac
109 exit 0