MCPcopy Create free account
hub / github.com/libgit2/pygit2 / ahead_behind

Method ahead_behind

pygit2/repository.py:1473–1506  ·  view source on GitHub ↗

Calculate how many different commits are in the non-common parts of the history between the two given ids. Ahead is how many commits are in the ancestry of the `local` commit which are not in the `upstream` commit. Behind is the opposite. Returns: a tuple o

(self, local: Oid | str, upstream: Oid | str)

Source from the content-addressed store, hash-verified

1471 # Ahead-behind, which mostly lives on its own namespace
1472 #
1473 def ahead_behind(self, local: Oid | str, upstream: Oid | str) -> tuple[int, int]:
1474 """
1475 Calculate how many different commits are in the non-common parts of the
1476 history between the two given ids.
1477
1478 Ahead is how many commits are in the ancestry of the `local` commit
1479 which are not in the `upstream` commit. Behind is the opposite.
1480
1481 Returns: a tuple of two integers with the number of commits ahead and
1482 behind respectively.
1483
1484 Parameters:
1485
1486 local
1487 The commit which is considered the local or current state.
1488
1489 upstream
1490 The commit which is considered the upstream.
1491 """
1492
1493 if not isinstance(local, Oid):
1494 local = self.expand_id(local)
1495
1496 if not isinstance(upstream, Oid):
1497 upstream = self.expand_id(upstream)
1498
1499 ahead, behind = ffi.new('size_t*'), ffi.new('size_t*')
1500 oid1, oid2 = ffi.new('git_oid *'), ffi.new('git_oid *')
1501 ffi.buffer(oid1)[:] = local.raw[:]
1502 ffi.buffer(oid2)[:] = upstream.raw[:]
1503 err = C.git_graph_ahead_behind(ahead, behind, self._repo, oid1, oid2)
1504 check_error(err)
1505
1506 return int(ahead[0]), int(behind[0])
1507
1508 #
1509 # Git attributes

Callers 1

test_ahead_behindFunction · 0.80

Calls 1

check_errorFunction · 0.85

Tested by 1

test_ahead_behindFunction · 0.64