MCPcopy Create free account
hub / github.com/google/git-appraise / FetchAndReturnNewReviewHashes

Method FetchAndReturnNewReviewHashes

repository/git.go:1111–1171  ·  view source on GitHub ↗

FetchAndReturnNewReviewHashes fetches the notes "branches" and then susses out the IDs (the revision the review points to) of any new reviews, then returns that list of IDs. This is accomplished by determining which files in the notes tree have changed because the _names_ of these files correspond

(remote, notesRefPattern string, devtoolsRefPatterns ...string)

Source from the content-addressed store, hash-verified

1109// changed because the _names_ of these files correspond to the revisions they
1110// point to.
1111func (repo *GitRepo) FetchAndReturnNewReviewHashes(remote, notesRefPattern string, devtoolsRefPatterns ...string) ([]string, error) {
1112 for _, refPattern := range devtoolsRefPatterns {
1113 if !strings.HasPrefix(refPattern, devtoolsRefPrefix) {
1114 return nil, fmt.Errorf("Unsupported devtools ref: %q", refPattern)
1115 }
1116 }
1117 remoteNotesRefPattern := getRemoteNotesRef(remote, notesRefPattern)
1118 notesFetchRefSpec := fmt.Sprintf("+%s:%s", notesRefPattern, remoteNotesRefPattern)
1119
1120 localDevtoolsRefPattern := devtoolsRefPrefix + "*"
1121 remoteDevtoolsRefPattern := getRemoteDevtoolsRef(remote, localDevtoolsRefPattern)
1122 devtoolsFetchRefSpec := fmt.Sprintf("+%s:%s", localDevtoolsRefPattern, remoteDevtoolsRefPattern)
1123
1124 // Prior to fetching, record the current state of the remote notes refs
1125 priorRefHashes, err := repo.getRefHashes(remoteNotesRefPattern)
1126 if err != nil {
1127 return nil, fmt.Errorf("failure reading the existing ref hashes for the remote %q: %v", remote, err)
1128 }
1129
1130 if err := repo.Fetch(remote, notesFetchRefSpec, devtoolsFetchRefSpec); err != nil {
1131 return nil, fmt.Errorf("failure fetching from the remote %q: %v", remote, err)
1132 }
1133
1134 // After fetching, record the updated state of the remote notes refs
1135 updatedRefHashes, err := repo.getRefHashes(remoteNotesRefPattern)
1136 if err != nil {
1137 return nil, fmt.Errorf("failure reading the updated ref hashes for the remote %q: %v", remote, err)
1138 }
1139
1140 // Now that we have our two lists, we need to merge them.
1141 updatedReviewSet := make(map[string]struct{})
1142 for ref, hash := range updatedRefHashes {
1143 priorHash, ok := priorRefHashes[ref]
1144 if priorHash == hash {
1145 // Nothing has changed for this ref
1146 continue
1147 }
1148 var notes string
1149 var err error
1150 if !ok {
1151 // This is a new ref, so include every noted object
1152 notes, err = repo.runGitCommand("ls-tree", "-r", "--name-only", hash)
1153 } else {
1154 notes, err = repo.runGitCommand("diff", "--name-only", priorHash, hash)
1155 }
1156 if err != nil {
1157 return nil, err
1158 }
1159 // The name of the review matches the name of the notes tree entry, with slashes removed
1160 reviews := strings.Split(strings.Replace(notes, "/", "", -1), "\n")
1161 for _, review := range reviews {
1162 updatedReviewSet[review] = struct{}{}
1163 }
1164 }
1165
1166 updatedReviews := make([]string, 0, len(updatedReviewSet))
1167 for key, _ := range updatedReviewSet {
1168 updatedReviews = append(updatedReviews, key)

Callers 1

PullNotesAndArchiveMethod · 0.95

Calls 5

getRefHashesMethod · 0.95
FetchMethod · 0.95
runGitCommandMethod · 0.95
getRemoteNotesRefFunction · 0.85
getRemoteDevtoolsRefFunction · 0.85

Tested by

no test coverage detected