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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
# (kgit-publish), (prepare a git tree for publication)
# Copyright (c) 2008-2012 Wind River Systems, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# For consistent behaviour with "grep -w"
LC_ALL=C
export LC_ALL
path=`dirname $0`
. $path/kgit
PATH=`cd $path; pwd`:$PATH
usage()
{
cat <<EOF
kgit-publish [-d] [-a] [-c] [-f] [--noauto] <src> <dest>
-c: compact. make the exported repository as small as possible
-d: description. put the description of the repository in place
when publishing
-f: force. if no checkpoint or other errors are found, publish
tree anyway. removes a destination repository if found.
removes working copy of source repository.
-a: auto checkpoint if required
--noauto: don't perform an automatic checkpoint
--reference: reference repo
Environment variables:
KMETA: defines the meta directory and branch. If not set, the
default is meta/meta
-h: Help
-v: Verbose
EOF
}
auto=t
while [ $# -gt 0 ]; do
case "$1" in
-v|--v)
verbose=t
;;
-c|--c)
compact=t
;;
-d|--d)
description="$2"
shift
;;
--reference)
ref="--reference $2"
shift
;;
-f|--f)
force=t
;;
-a|--a)
auto=t
;;
--noauto)
auto=
;;
-h|--h)
usage
exit
;;
*)
break
;;
esac
shift
done
if [ ! $# -gt 1 ]; then
usage
exit 1
fi
src=$1
dest=$2
meta_dir=$KMETA
checkpoint_branch=$KMETA
if [ -z "$meta_dir" ]; then
meta_dir=meta
checkpoint_branch=meta
fi
if [ ! -d "$dest" ] || [ -n "$force" ]; then
if [ -d "$dest" ]; then
echo "[INFO] removing dest repository at $dest"
rm -rf "$dest"
fi
SRCTMP=`mktemp -d --tmpdir=./`
if [ $? != 0 ]; then
echo "[ERROR] mktemp failed"
exit -1
fi
if [ -n "$verbose" ]; then
echo "[INFO] making working copy of $src in $SRCTMP"
fi
cp -a $src $SRCTMP
if [ $? != 0 ]; then
echo "[ERROR] making working copy of $src failed"
exit -1
fi
# now we only operate on temp copy
src=$SRCTMP/$src
x=`cd $src; git show-ref checkpoint_start`
if [ -z "$x" ]; then
x=`cd $src; git show-ref checkpoint`
fi
if [ -z "$x" ]; then
if [ -n "$auto" ]; then
if [ -n "$verbose" ]; then
echo "[INFO] checkpointing repository"
fi
(cd $src; kgit checkpoint -b $checkpoint_branch -c)
if [ $? != 0 ]; then
echo "[ERROR] checkpoint failed"
exit 1
fi
auto_checked=t
else
if [ -z "$force" ]; then
echo ""
echo "[ERROR] checkpoint not found, cannot publish this tree"
echo ""
exit 1
fi
fi
fi
if [ -n "$verbose" ]; then
echo "[INFO] creating published repository $dest"
fi
git clone --bare $ref $src $dest
else
echo "[INFO] $dest exists, and --force was not passed. nothing to do"
exit 0
fi
if [ -d $dest ]; then
old=`pwd`
cd $dest
if [ -n "$description" ]; then
echo "$description" > description
fi
if [ ! -z "$compact" ]; then
git gc --aggressive --prune
git prune
fi
cd $old
fi
if [ -n "$auto_checked" ]; then
(cd $src; kgit checkpoint -b $checkpoint_branch -r)
if [ $? != 0 ]; then
echo "[ERROR] checkpoint restore failed"
exit 1
fi
fi
if [ -n "$force" ]; then
echo "[INFO] removing $src"
rm -rf $src
fi
|