view scripts/repo_update @ 4:ef2b8d975a99

exec time vs task size data generation and calculation splited in two scripts
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 12 Dec 2011 20:26:28 +0100
parents
children
line source
1 #! /bin/bash
3 usage=$(cat << EOF
5 Usage: $0 [-h] [-a] [-r] [-k] [-w] [-b Commit/Tag/Branch]
7 -a Apply all the changes to all repositories in the current tree.
9 -b Update to a commit/tag/branch. This is useful if you work on a single
10 branch/tag in all repositories. If the requested repository is not
11 found it falls back to the recent version. The -k and -i options are
12 useful here.
14 -h Prints this usage information
16 -i Update to a commit/tag/branch with the -b flag in interactive mode.
17 This asks if you want to fall back to the recent version if the
18 requested commit/tag/branch is not found.
19 This is only useful with the -b flag.
21 -k This does not pull from the remote repository, just updates the
22 repositories.
24 -r Revert to the last version. This is not deleting the pull commit,
25 just updating back to your last state.
27 -w Do the pull over https instead of ssh
28 EOF
29 )
31 SAVED_STATE_FILE=~/.hg.saved
33 #set selected repository to current folder
34 SELECTED_REPOS=$(pwd)
36 source repo_update_helper.sh
38 #################################
39 #Parse arguments
40 #################################
41 while getopts "arb:hikw" flag
42 do
43 case $flag in
44 a)
45 #update all repositories in the directory tree
46 SELECTED_REPOS=$(find_repos)
47 ;;
48 r)
49 #revert to commits after the last pull from the server
50 REVERT="1"
51 ;;
52 b)
53 #update to a tag/branch/commit
54 VERSION=$OPTARG
55 ;;
56 k)
57 NO_UPDATE="1"
58 ;;
59 i)
60 INTERACTIVE_UPDATE="1"
61 ;;
62 w)
63 REMOTE="http"
64 ;;
65 h)
66 echo "$usage"
67 exit 0
68 ;;
69 *)
70 echo "$usage"
71 exit 0
72 ;;
73 esac
74 done
76 if [ ! -e $SAVED_STATE_FILE ]
77 then
78 touch $SAVED_STATE_FILE
79 fi
80 SAVED_STATE=$(cat $SAVED_STATE_FILE | sed "s/^$//g")
81 BASE_FOLDER=$(pwd)
83 #################################
84 # Revert changes and exit.
85 #################################
86 if [ -n "$REVERT" ]
87 then
88 print_info "Reverting changes"
89 for REPO in $SELECTED_REPOS
90 do
91 cd $REPO
92 pwd
94 REVERT_COMMIT=$(echo "$SAVED_STATE" | grep "$PWD " | grep -o -E "[a-z0-9]{12}")
95 if [ -z "$REVERT_COMMIT" ]
96 then
97 echo "No saved commit."
98 cd $BASE_FOLDER
99 continue
100 fi
101 hg update $REVERT_COMMIT
103 cd $BASE_FOLDER
104 done
105 exit 0
106 fi
108 #################################
109 # Save the current current state of the repository
110 #################################
111 print_info "Saving current commit."
112 for REPO in $SELECTED_REPOS
113 do
114 cd $REPO
115 pwd
116 if [ 0 -ne $? ]
117 then
118 echo "Cannot change to repository $REPO"
119 exit 1
120 fi
122 STATE=$(hg summary)
123 if [ 0 -ne $? ]
124 then
125 echo "Not a repository: $REPO"
126 exit 1
127 fi
128 CURRENT_COMMIT=$(echo "$STATE" | grep -o -E "[0-9]:[a-z0-9]{12}" | grep -o -E "[a-z0-9]{12}")
130 #remove current repository from saved state
131 SAVED_STATE=$(echo "$SAVED_STATE" | grep -v "$PWD ")
132 SAVED_STATE=$(echo -e "$SAVED_STATE" && echo "$PWD $CURRENT_COMMIT")
134 cd $BASE_FOLDER
135 done
136 echo "$SAVED_STATE" > $SAVED_STATE_FILE
138 #################################
139 # Pull changes from remote server.
140 #################################
141 if [ -z "$NO_UPDATE" ]
142 then
143 print_info "Pull changes from remote."
144 for REPO in $SELECTED_REPOS
145 do
146 cd $REPO
147 pwd
148 hg pull $REMOTE
149 if [ 0 -ne $? ]
150 then
151 echo "An issue occured while pulling changes from remote server."
152 exit 1
153 fi
155 cd $BASE_FOLDER
156 done
157 fi
159 #################################
160 # Update repository to most recent version
161 #################################
162 print_info "Updating repositories."
163 for REPO in $SELECTED_REPOS
164 do
165 cd $REPO
166 pwd
168 if [ -n "$VERSION" ]
169 then
170 hg update $VERSION
171 if [ 0 -ne $? ]
172 then
173 #update not possible. falling back to recent version or interactive mode
174 if [ -n "$INTERACTIVE_UPDATE" ]
175 then
176 while true
177 do
178 read -p "Fallback to recent version? [y/n]: " answer
179 if [ "$answer" = "y" ]
180 then
181 hg update
182 break
183 fi
184 if [ "$answer" = "n" ]
185 then
186 echo "Not updated."
187 break
188 fi
189 done
190 else
191 hg update
192 fi
193 fi
194 else
195 hg update
196 fi
197 if [ 0 -ne $? ]
198 then
199 echo "Error updating the repository."
200 exit 1
201 fi
203 cd $BASE_FOLDER
204 done