Debian Codegraph @

tools/dist/edit-N-log-messages

raw
1 #!/usr/bin/env zsh
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18
19 set -e
20
21 # setup
22 0=${0:t}; NAME=$0
23 svn=${SVN:-svn}
24 svnadmin=${SVNADMIN:-svnadmin}
25
26 usage() {
27 echo "usage: $NAME -r N:M"
28 echo " will retrieve all log messages in the range rN:rM, open them in"
29 echo " \$EDITOR, and commit any edits to them."
30 echo ""
31 echo " Run this with cwd being a working copy of ^/subversion/trunk."
32 # TODO: We only need the cwd in case SVN_CLIENT__REVKIND_NEEDS_WC() is true
33 # for N or M. When N and M are both numeric or HEAD, teach this script
34 # to disregard its cwd and contact ^/subversion/trunk directly.
35 }
36
37 # parse argv
38 while getopts r: letter; do
39 if [[ $letter == r ]]; then
40 revision_range=$OPTARG
41 else
42 usage >&2
43 exit 1
44 fi
45 done
46 shift $((OPTIND - 1))
47 [[ -n $revision_range ]] || { usage >&2; exit 1; }
48
49 # get log messages
50 cd "$(mktemp -d)"
51 echo "${0}: Temporary directory: ${(q-)PWD}"
52 revisions=( ${(f)"$(
53 # We use $OLDPWD rather than a URL in case $revision_range is, say,
54 # "BASE:HEAD".
55 $svn log -q -r $revision_range -- $OLDPWD |
56 grep '^r' | cut -d' ' -f1 | grep '^r[0-9]*$'
57 )"} )
58 for rN in $revisions; do
59 $svn propget --revprop -r $rN --strict 'svn:log' -- $OLDPWD > ./$rN &
60 done
61 wait
62
63 # set up to detect which ones have changed
64 $svnadmin create ./.r
65 $svn checkout -q file://$PWD/.r ./
66 $svn add -q ./r*
67 $svn commit -q -m "Import revisions $revision_range"
68 rm -rf ./.r # (!)
69
70 # edit
71 case $EDITOR in
72 (*vim*) $EDITOR -p ./r*;;
73 (*) $EDITOR ./r*;;
74 esac
75
76 # prompt for permission to continue
77 if $svn status -q | grep -q ''; then
78 $svn status -q
79 read -q "?Commit the above propedits? " || { echo "${0}: exiting"; exit 0; }
80 echo ""
81 else
82 echo "${0}: No changes."
83 echo "${0}: You can remove ${(q-)PWD} now."
84 exit 0
85 fi
86
87 # make propedits
88 # TODO: make these changes atomically
89 # 'svn propedit' is atomic and could drive a non-interactive $EDITOR, but for
90 # now, we just trust the committer to read commits@.
91 targets=( ${(f)"$($svn status -q | grep '^M' | cut -c9-)"} )
92 for i in $targets; do
93 $svn propset --revprop -r $i -F ./$i -- 'svn:log' $OLDPWD
94 done