Updated Russian translation.
[midnight-commander.git] / src / vfs / extfs / helpers / changesetfs
blob3c06d0b72983314d708a469c4f5683c99edda3c3
1 #!/bin/sh
3 LANG=C
4 export LANG
6 # --- GIT -----------------------------------------------------------------------
8 found_git_dir()
10 work_dir=$1
11 while [ -n "$work_dir" -a "$work_dir" != "/" ]; do
12 [ -d "${work_dir}/.git" ] && {
13 echo "${work_dir}/.git/"
14 return
16 work_dir=`dirname "$work_dir"`
17 done
18 echo ''
21 changesetfs_list_git()
23 WORK_DIR=$1; shift
24 fname=$1; shift
25 USER=$1; shift
26 DATE=$1; shift
28 GIT_DIR=`found_git_dir "$WORK_DIR"`
29 [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR
30 curr_year=`date +"%Y"`
32 git --git-dir="$GIT_DIR" log --abbrev=7 --pretty="format:%at %h %an" -- "$fname" | while read TIMESTAMP chset author
34 year=`date -d @"$TIMESTAMP" +"%Y"`
35 [ "$year" = "$curr_year" ] && {
36 DATE=`date -d @"$TIMESTAMP" +"%b %d %H:%M"`
37 } || {
38 DATE=`date -d @"$TIMESTAMP" +"%b %d %Y"`
40 NAME="$chset $author"
41 echo "-rw-rw-rw- 1 $USER 0 0 $DATE $NAME `basename $fname`"
42 done
45 changesetfs_copyout_git()
47 WORK_DIR=$1; shift
48 fname=$1; shift
49 orig_fname=$1;shift
50 output_fname=$1;shift
52 chset=`echo "$orig_fname"| cut -f 1 -d " "`
54 GIT_DIR=`found_git_dir "$WORK_DIR"`
55 [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR
57 filecommit=`git --git-dir="$GIT_DIR" show --raw --pretty=tformat:%h "$chset" -- "$fname"| \
58 tail -n1 | \
59 sed 's@^::[0-9]*\s*[0-9]*\s*[0-9]*\s*@@' | \
60 sed 's@^:[0-9]*\s*[0-9]*\s*@@' | \
61 cut -d'.' -f 1`
62 git --git-dir="$GIT_DIR" show "$filecommit" > "$output_fname"
65 # --- COMMON --------------------------------------------------------------------
67 changesetfs_list()
69 VCS_type=$1; shift
70 WORK_DIR=$1; shift
71 fname=$1; shift
73 DATE=`date +"%b %d %H:%M"`
74 USER=`whoami`
76 case "$VCS_type" in
77 git) changesetfs_list_git "$WORK_DIR" "$fname" "$USER" "$DATE" ;;
78 esac
81 changesetfs_copyout()
83 VCS_type=$1; shift
84 WORK_DIR=$1; shift
85 fname=$1; shift
87 case "$VCS_type" in
88 git) changesetfs_copyout_git "$WORK_DIR" "$fname" "$@" ;;
89 esac
93 # --- MAIN ----------------------------------------------------------------------
95 command=$1; shift
96 tmp_file=$1; shift
98 WORK_DIR=`head -n1 $tmp_file`
99 fname=`tail -n2 $tmp_file | head -n1`
100 VCS_type=`tail -n1 $tmp_file`
102 case "$command" in
103 list) changesetfs_list "$VCS_type" "$WORK_DIR" "$fname" ;;
104 copyout) changesetfs_copyout "$VCS_type" "$WORK_DIR" "$fname" "$@" ;;
105 *) exit 1 ;;
106 esac
107 exit 0