本文整理匯總了Python中objects.Object.new方法的典型用法代碼示例。如果您正苦於以下問題:Python Object.new方法的具體用法?Python Object.new怎麽用?Python Object.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類objects.Object
的用法示例。
在下文中一共展示了Object.new方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create
# 需要導入模塊: from objects import Object [as 別名]
# 或者: from objects.Object import new [as 別名]
def _create(cls, repo, path, resolve, reference, force):
"""internal method used to create a new symbolic reference.
If resolve is False,, the reference will be taken as is, creating
a proper symbolic reference. Otherwise it will be resolved to the
corresponding object and a detached symbolic reference will be created
instead"""
full_ref_path = cls.to_full_path(path)
abs_ref_path = os.path.join(repo.git_dir, full_ref_path)
# figure out target data
target = reference
if resolve:
target = Object.new(repo, reference)
if not force and os.path.isfile(abs_ref_path):
target_data = str(target)
if isinstance(target, SymbolicReference):
target_data = target.path
if not resolve:
target_data = "ref: " + target_data
if open(abs_ref_path, 'rb').read().strip() != target_data:
raise OSError("Reference at %s does already exist" % full_ref_path)
# END no force handling
ref = cls(repo, full_ref_path)
ref.reference = target
return ref
示例2: _get_object
# 需要導入模塊: from objects import Object [as 別名]
# 或者: from objects.Object import new [as 別名]
def _get_object(self):
"""
Returns
The object our ref currently refers to. Refs can be cached, they will
always point to the actual object as it gets re-created on each query
"""
# have to be dynamic here as we may be a tag which can point to anything
# Our path will be resolved to the hexsha which will be used accordingly
return Object.new(self.repo, self.path)
示例3: _set_reference
# 需要導入模塊: from objects import Object [as 別名]
# 或者: from objects.Object import new [as 別名]
def _set_reference(self, ref):
"""
Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
Otherwise we try to get a commit from it using our interface.
Strings are allowed but will be checked to be sure we have a commit
"""
write_value = None
if isinstance(ref, SymbolicReference):
write_value = "ref: %s" % ref.path
elif isinstance(ref, Commit):
write_value = ref.sha
else:
try:
write_value = ref.commit.sha
except AttributeError:
sha = str(ref)
try:
obj = Object.new(self.repo, sha)
if obj.type != "commit":
raise TypeError("Invalid object type behind sha: %s" % sha)
write_value = obj.sha
except Exception:
raise ValueError("Could not extract object from %s" % ref)
# END end try string
# END try commit attribute
# if we are writing a ref, use symbolic ref to get the reflog and more
# checking
# Otherwise we detach it and have to do it manually
if write_value.startswith('ref:'):
self.repo.git.symbolic_ref(self.path, write_value[5:])
return
# END non-detached handling
path = self._get_path()
directory = os.path.dirname(path)
if not os.path.isdir(directory):
os.makedirs(directory)
fp = open(path, "wb")
try:
fp.write(write_value)
finally:
fp.close()