MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / getSyncStatusOfBranch

Method getSyncStatusOfBranch

plugins/vcs/Repository.cpp:204–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204RefSyncStatus Repository::getSyncStatusOfBranch(const Reference& reference)
205{
206 RefSyncStatus status;
207
208 auto trackedBranch = reference.getUpstream();
209
210 if (!trackedBranch) throw GitException(_("The current branch doesn't track a remote, cannot check sync status"));
211
212 git_revwalk* walker = nullptr;
213 git_revwalk_new(&walker, _repository);
214
215 // Start from remote
216 git_revwalk_push_ref(walker, trackedBranch->getName().c_str());
217
218 // End at local
219 git_oid refOid;
220 git_reference_name_to_id(&refOid, _repository, reference.getName().c_str());
221 git_revwalk_hide(walker, &refOid);
222
223 git_oid id;
224 while (!git_revwalk_next(&id, walker))
225 {
226 //rMessage() << Reference::OidToString(&id) << " => ";
227 ++status.remoteCommitsAhead;
228 }
229 //rMessage() << std::endl;
230
231 git_revwalk_free(walker);
232
233 // Another walk from local to remote
234 git_revwalk_new(&walker, _repository);
235
236 git_revwalk_push(walker, &refOid);
237 git_revwalk_hide_ref(walker, trackedBranch->getName().c_str());
238
239 while (!git_revwalk_next(&id, walker))
240 {
241 //rMessage() << Reference::OidToString(&id) << " => ";
242 ++status.localCommitsAhead;
243 }
244 //rMessage() << std::endl;
245
246 git_revwalk_free(walker);
247
248 // Initialise the convenience flags
249 status.localIsUpToDate = status.localCommitsAhead == 0 && status.remoteCommitsAhead == 0;
250 status.localCanBePushed = status.localCommitsAhead > 0 && status.remoteCommitsAhead == 0;
251
252 return status;
253}
254
255bool Repository::isUpToDateWithRemote()
256{

Callers 1

analyseRemoteStatusFunction · 0.80

Calls 5

GitExceptionClass · 0.85
getUpstreamMethod · 0.80
_Function · 0.50
c_strMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected