Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if committish:
if isinstance(committish, str):
committish = self.revparse_single(committish)
commit = committish.peel(Commit)
cptr = ffi.new('git_object **')
ffi.buffer(cptr)[:] = commit._pointer[:]
err = C.git_describe_commit(result, cptr[0], options)
else:
err = C.git_describe_workdir(result, self._repo, options)
check_error(err)
try:
format_options = ffi.new('git_describe_format_options *')
C.git_describe_init_format_options(format_options, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)
if abbreviated_size is not None:
format_options.abbreviated_size = abbreviated_size
if always_use_long_format is not None:
format_options.always_use_long_format = always_use_long_format
dirty_ptr = None
if dirty_suffix:
dirty_ptr = ffi.new('char[]', to_bytes(dirty_suffix))
format_options.dirty_suffix = dirty_ptr
buf = ffi.new('git_buf *', (ffi.NULL, 0))
err = C.git_describe_format(buf, result[0], format_options)
check_error(err)
Index that reflects the result of the revert.
Returns: an Index with the result of the revert.
Parameters:
revert_commit
The Commit to revert.
our_commit
The Commit to revert against (eg, HEAD).
mainline
The parent of the revert Commit, if it is a merge (i.e. 1, 2).
"""
cindex = ffi.new('git_index **')
revert_commit_ptr = ffi.new('git_commit **')
our_commit_ptr = ffi.new('git_commit **')
ffi.buffer(revert_commit_ptr)[:] = revert_commit._pointer[:]
ffi.buffer(our_commit_ptr)[:] = our_commit._pointer[:]
opts = ffi.new('git_merge_options *')
err = C.git_merge_init_options(opts, C.GIT_MERGE_OPTIONS_VERSION)
check_error(err)
err = C.git_revert_commit(
cindex, self._repo, revert_commit_ptr[0], our_commit_ptr[0], mainline, opts
)
check_error(err)
return Index.from_c(self, cindex)
def rename(self, name, new_name):
"""Rename a remote in the configuration. The refspecs in standard
format will be renamed.
Returns a list of fetch refspecs (list of strings) which were not in
the standard format and thus could not be remapped.
"""
if not new_name:
raise ValueError("Current remote name must be a non-empty string")
if not new_name:
raise ValueError("New remote name must be a non-empty string")
problems = ffi.new('git_strarray *')
err = C.git_remote_rename(problems, self._repo._repo, to_bytes(name), to_bytes(new_name))
check_error(err)
ret = strarray_to_strings(problems)
C.git_strarray_free(problems)
return ret
def __iter__(self):
names = ffi.new('git_strarray *')
try:
err = C.git_remote_list(names, self._repo._repo)
check_error(err)
cremote = ffi.new('git_remote **')
for i in range(names.count):
err = C.git_remote_lookup(cremote, self._repo._repo, names.strings[i])
check_error(err)
yield Remote(self._repo, cremote[0])
finally:
C.git_strarray_free(names)
def get_multivar(self, name, regex=None):
"""Get each value of a multivar ''name'' as a list of strings.
The optional ''regex'' parameter is expected to be a regular expression
to filter the variables we're interested in.
"""
assert_string(name, "name")
citer = ffi.new('git_config_iterator **')
err = C.git_config_multivar_iterator_new(citer, self._config,
to_bytes(name),
to_bytes(regex))
check_error(err)
return ConfigMultivarIterator(self, citer[0])
def _get(self, key):
assert_string(key, "key")
entry = ffi.new('git_config_entry **')
err = C.git_config_get_entry(entry, self._config, to_bytes(key))
return err, ConfigEntry._from_c(entry[0])
def _checkout_args_to_options(strategy=None, directory=None, paths=None):
# Create the options struct to pass
copts = ffi.new('git_checkout_options *')
check_error(C.git_checkout_init_options(copts, 1))
# References we need to keep to strings and so forth
refs = []
# pygit2's default is SAFE | RECREATE_MISSING
copts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING
# and go through the arguments to see what the user wanted
if strategy:
copts.checkout_strategy = strategy
if directory:
target_dir = ffi.new('char[]', to_bytes(directory))
refs.append(target_dir)
copts.target_directory = target_dir
if paths:
strarray = StrArray(paths)
refs.append(strarray)
copts.paths = strarray.array[0]
return copts, refs
def lookup_submodule(self, path):
csub = ffi.new('git_submodule **')
cpath = ffi.new('char[]', to_bytes(path))
err = C.git_submodule_lookup(csub, self._repo, cpath)
check_error(err)
return Submodule._from_c(self, csub[0])