parseRemoteUpdateOutput detects create, update and delete operations of references from upstream.
(output string)
| 172 | |
| 173 | // parseRemoteUpdateOutput detects create, update and delete operations of references from upstream. |
| 174 | func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { |
| 175 | results := make([]*mirrorSyncResult, 0, 3) |
| 176 | lines := strings.Split(output, "\n") |
| 177 | for i := range lines { |
| 178 | // Make sure reference name is presented before continue |
| 179 | idx := strings.Index(lines[i], "-> ") |
| 180 | if idx == -1 { |
| 181 | continue |
| 182 | } |
| 183 | |
| 184 | refName := lines[i][idx+3:] |
| 185 | switch { |
| 186 | case strings.HasPrefix(lines[i], " * "): // New reference |
| 187 | results = append(results, &mirrorSyncResult{ |
| 188 | refName: refName, |
| 189 | oldCommitID: gitShortEmptyID, |
| 190 | }) |
| 191 | case strings.HasPrefix(lines[i], " - "): // Delete reference |
| 192 | results = append(results, &mirrorSyncResult{ |
| 193 | refName: refName, |
| 194 | newCommitID: gitShortEmptyID, |
| 195 | }) |
| 196 | case strings.HasPrefix(lines[i], " "): // New commits of a reference |
| 197 | delimIdx := strings.Index(lines[i][3:], " ") |
| 198 | if delimIdx == -1 { |
| 199 | log.Error("SHA delimiter not found: %q", lines[i]) |
| 200 | continue |
| 201 | } |
| 202 | shas := strings.Split(lines[i][3:delimIdx+3], "..") |
| 203 | if len(shas) != 2 { |
| 204 | log.Error("Expect two SHAs but not what found: %q", lines[i]) |
| 205 | continue |
| 206 | } |
| 207 | results = append(results, &mirrorSyncResult{ |
| 208 | refName: refName, |
| 209 | oldCommitID: shas[0], |
| 210 | newCommitID: shas[1], |
| 211 | }) |
| 212 | |
| 213 | default: |
| 214 | log.Warn("parseRemoteUpdateOutput: unexpected update line %q", lines[i]) |
| 215 | } |
| 216 | } |
| 217 | return results |
| 218 | } |
| 219 | |
| 220 | // mirrorGitArgs returns the git-level arguments used by every remote network |
| 221 | // operation against a mirror source. |