Browse code

smarter mirroring respects forks

Nat! authored on 22-06-2017 20:52:42
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+### 3.7.1
2
+
3
+* save git mirrors under their fork names
4
+
1 5
 ## 3.7.0
2 6
 
3 7
 * experimentally added ${GITHUB_REMOTE_ORIGIN} expansion, so you can specify
... ...
@@ -31,7 +31,7 @@
31 31
 #
32 32
 MULLE_EXECUTABLE_VERSION_MAJOR=3
33 33
 MULLE_EXECUTABLE_VERSION_MINOR=7
34
-MULLE_EXECUTABLE_VERSION_PATCH=0
34
+MULLE_EXECUTABLE_VERSION_PATCH=1
35 35
 
36 36
 MULLE_EXECUTABLE_VERSION="${MULLE_EXECUTABLE_VERSION_MAJOR}.${MULLE_EXECUTABLE_VERSION_MINOR}.${MULLE_EXECUTABLE_VERSION_PATCH}"
37 37
 
... ...
@@ -171,6 +171,32 @@ git_checkout()
171 171
 }
172 172
 
173 173
 
174
+fork_and_name_from_url()
175
+{
176
+   local url="$1"
177
+   local name
178
+   local hack
179
+   local fork
180
+
181
+   hack="`sed 's|^[^:]*:|:|' <<< "${url}"`"
182
+   name="`basename -- "${hack}"`"
183
+   fork="`dirname -- "${hack}"`"
184
+   fork="`basename -- "${fork}"`"
185
+
186
+   case "${hack}" in
187
+      /*/*|:[^/]*/*|://*/*/*)
188
+      ;;
189
+
190
+      *)
191
+         fork="__other__"
192
+      ;;
193
+   esac
194
+
195
+   echo "${fork}" | sed 's|^:||'
196
+   echo "${name}"
197
+}
198
+
199
+
174 200
 
175 201
 # global variable __GIT_MIRROR_URLS__ used to avoid refetching
176 202
 # repos in one setting
... ...
@@ -179,10 +205,18 @@ _git_get_mirror_url()
179 205
 {
180 206
    local url="$1"; shift
181 207
 
208
+   local name
209
+   local fork
210
+   local result
211
+
212
+   result="`fork_and_name_from_url "${url}"`"
213
+   fork="`echo "${result}" | head -1`"
214
+   name="`echo "${result}" | tail -1`"
215
+
182 216
    local mirrordir
183 217
 
184
-   mkdir_if_missing "${GIT_MIRROR}"
185
-   mirrordir="${GIT_MIRROR}/`basename ${url}`" # try to keep it global
218
+   mkdir_if_missing "${GIT_MIRROR}/${fork}"
219
+   mirrordir="${GIT_MIRROR}/${fork}/${name}" # try to keep it global
186 220
 
187 221
    local match
188 222
    local filelistpath
... ...
@@ -266,7 +300,7 @@ _git_clone()
266 300
       *:*)
267 301
          if [ ! -z "${GIT_MIRROR}" ]
268 302
          then
269
-            url="`_git_get_mirror_url "${url}"`"
303
+            url="`_git_get_mirror_url "${url}"`" || return 1
270 304
          fi
271 305
       ;;
272 306
    esac
... ...
@@ -339,7 +373,7 @@ git_fetch()
339 373
       *:*)
340 374
          if [ ! -z "${GIT_MIRROR}" ]
341 375
          then
342
-            url="`_git_get_mirror_url ${url}`"
376
+            url="`_git_get_mirror_url ${url}`" || return 1
343 377
          fi
344 378
       ;;
345 379
    esac
... ...
@@ -373,7 +407,7 @@ git_pull()
373 407
       *:*)
374 408
          if [ ! -z "${GIT_MIRROR}" ]
375 409
          then
376
-            url="`_git_get_mirror_url ${url}`"
410
+            url="`_git_get_mirror_url ${url}`" || return 1
377 411
          fi
378 412
       ;;
379 413
    esac