This allows for efficient reading of many references and their targets,
without incurring the overhead of lookup_reference() (which stats for
a loose ref and then reads packed-refs) which can be expensive on NFS
with thousands of refs.
Updating the target of a reference is not like setting a property. It
involves appending to the reflog under the same lock, so we must do it
all the same time. Thus setting the target becomes a function which
takes the new target and what the use would like to add to the reflog.
Now we figure out whether it is a direct or symbolic reference based on
the type and value of the target. This guessing will fail in very very
rare situations, for that we still have the explicit lower level API.
Two methods have been drop:
- Repository.packall_references
- Reference.reload
The unit tests have been commented until we wrap the new reference
database from libgit2.
To be more pythonic: merged methods create_reference and create_reference_symbolic
and added force-Option. To make a new symbolic reference you have provide symbolic=True
as an additional parameter. If force=True references will although be overridden.
Otherwise an exception is raised if the references exists.
Examples:
# normal reference
repo.create_reference('refs/heads/foo', repo.head.hex)
# override reference with new value
repo.create_reference('refs/heads/foo', repo.head.hex, force=True)
# symbolic reference
repo.create_reference('refs/tags/foo', 'refs/heads/master', symbolic = True)
You do not have to lookup and resolve the HEAD reference anymore if you simply want
the last commit. Repository has now a head-getter which combines all these steps.
example:
repo = Repository('.')
head = repo.head
print(head.message)