summaryrefslogtreecommitdiffstats
path: root/src/vfs/extfs/helpers/patchsetfs
blob: 9bbe9f97d32f3e0e43b0bea8b76015a8f4ffb8ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh

LANG=C
export LANG
LC_TIME=C
export LC_TIME

# --- GIT -----------------------------------------------------------------------

found_git_dir()
{
    work_dir=$1
    while [ -n "$work_dir" -a "$work_dir" != "/" ]; do
        [ -d "${work_dir}/.git" ] && {
            echo "${work_dir}/.git/"
            return
        }
        work_dir=`dirname "$work_dir"`
    done
    echo ''
}

patchsetfs_list_git()
{
    WORK_DIR=$1; shift
    fname=$1; shift
    USER=$1; shift
    DATE=$1; shift

    GIT_DIR=`found_git_dir "$WORK_DIR"`
    [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR
    curr_year=`date +"%Y"`

    git --git-dir="$GIT_DIR" log --abbrev=7 --pretty="format:%at %h %an" -- "$fname" | while read TIMESTAMP chset author
    do
        year=`date -d @"$TIMESTAMP" +"%Y"`
        [ "$year" = "$curr_year" ] && {
            DATE=`date -d @"$TIMESTAMP" +"%b %d %H:%M"`
        } || {
            DATE=`date -d @"$TIMESTAMP" +"%b %d %Y"`
        }
        NAME="$chset $author"
        echo "-rw-rw-rw-   1 $USER    0 0 $DATE  $NAME.diff"
    done
}

patchsetfs_copyout_git()
{
    WORK_DIR=$1; shift
    fname=$1; shift
    orig_fname=$1;shift
    output_fname=$1;shift

    chset=`echo "$orig_fname"| cut -f 1 -d " "`

    GIT_DIR=`found_git_dir "$WORK_DIR"`
    [ -z "$GIT_DIR" ] && GIT_DIR=$WORK_DIR

    git  --git-dir="$GIT_DIR" show "$chset" -- "$fname" > "$output_fname"
}

# --- COMMON --------------------------------------------------------------------

patchsetfs_list()
{
    VCS_type=$1; shift
    WORK_DIR=$1; shift
    fname=$1; shift

    DATE=`date +"%b %d %H:%M"`
    USER=`whoami`

    case "$VCS_type" in
        git) patchsetfs_list_git "$WORK_DIR" "$fname" "$USER" "$DATE" ;;
    esac
}

patchsetfs_copyout()
{
    VCS_type=$1; shift
    WORK_DIR=$1; shift
    fname=$1; shift

    case "$VCS_type" in
        git) patchsetfs_copyout_git "$WORK_DIR" "$fname" "$@" ;;
    esac

}

# --- MAIN ----------------------------------------------------------------------

command=$1; shift
tmp_file=$1; shift

WORK_DIR=`head -n1 $tmp_file`
fname=`tail -n2 $tmp_file | head -n1`
VCS_type=`tail -n1 $tmp_file`

case "$command" in
  list) patchsetfs_list "$VCS_type" "$WORK_DIR" "$fname" ;;
  copyout) patchsetfs_copyout "$VCS_type" "$WORK_DIR" "$fname" "$@" ;;
  *) exit 1 ;;
esac
exit 0