8000 Add and use StrArray.ptr() · libgit2/pygit2@ed3a6b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed3a6b2

Browse files
committed
Add and use StrArray.ptr()
To emphasize that the StrArray() context manager returns a pointer, implement its ptr() property and use it whenever calling a C function that takes a pointer to a git_strarray structure as a parameter.
1 parent be6945c commit ed3a6b2

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pygit2/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def remove(self, path, level=0):
179179
def remove_all(self, pathspecs):
180180
"""Remove all index entries matching pathspecs."""
181181
with StrArray(pathspecs) as arr:
182-
err = C.git_index_remove_all(self._index, arr, ffi.NULL, ffi.NULL)
182+
err = C.git_index_remove_all(self._index, arr.ptr, ffi.NULL, ffi.NULL)
183183
check_error(err, io=True)
184184

185185
def add_all(self, pathspecs=None):
@@ -190,7 +190,7 @@ def add_all(self, pathspecs=None):
190190
"""
191191
pathspecs = pathspecs or []
192192
with StrArray(pathspecs) as arr:
193-
err = C.git_index_add_all(self._index, arr, 0, ffi.NULL, ffi.NULL)
193+
err = C.git_index_add_all(self._index, arr.ptr, 0, ffi.NULL, ffi.NULL)
194194
check_error(err, io=True)
195195

196196
def add(self, path_or_entry):

pygit2/remotes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def fetch(
155155
opts.depth = depth
156156
self.__set_proxy(opts.proxy_opts, proxy)
157157
with StrArray(refspecs) as arr:
158-
err = C.git_remote_fetch(self._remote, arr, opts, to_bytes(message))
158+
err = C.git_remote_fetch(self._remote, arr.ptr, opts, to_bytes(message))
159159
payload.check_error(err)
160160

161161
return TransferProgress(C.git_remote_stats(self._remote))
@@ -265,7 +265,7 @@ def push(self, specs, callbacks=None, proxy=None):
265265
opts = payload.push_options
266266
self.__set_proxy(opts.proxy_opts, proxy)
267267
with StrArray(specs) as refspecs:
268-
err = C.git_remote_push(self._remote, refspecs, opts)
268+
err = C.git_remote_push(self._remote, refspecs.ptr, opts)
269269
payload.check_error(err)
270270

271271
def __set_proxy(self, proxy_opts, proxy):

pygit2/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class StrArray:
8787
8000 list of strings. This has a context manager, which you should use, e.g.
8888
8989
with StrArray(list_of_strings) as arr:
90-
C.git_function_that_takes_strarray(arr)
90+
C.git_function_that_takes_strarray(arr.ptr)
9191
"""
9292

9393
def __init__(self, l):
@@ -112,11 +112,15 @@ def __init__(self, l):
112112
self.array = ffi.new('git_strarray *', [self._arr, len(strings)])
113113

114114
def __enter__(self):
115-
return self.array
115+
return self
116116

117117
def __exit__(self, type, value, traceback):
118118
pass
119119

120+
@property
121+
def ptr(self):
122+
return self.array
123+
120124

121125
class GenericIterator:
122126
"""Helper to easily implement an iterator.

0 commit comments

Comments
 (0)
0