Skip to content

Commit 88580c2

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 6b2eb38 commit 88580c2

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))
@@ -263,7 +263,7 @@ def push(self, specs, callbacks=None, proxy=None):
263263
opts = payload.push_options
264264
self.__set_proxy(opts.proxy_opts, proxy)
265265
with StrArray(specs) as refspecs:
266-
err = C.git_remote_push(self._remote, refspecs, opts)
266+
err = C.git_remote_push(self._remote, refspecs.ptr, opts)
267267
payload.check_error(err)
268268

269269
def __set_proxy(self, proxy_opts, proxy):

pygit2/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class StrArray:
9292
list of strings. This has a context manager, which you should use, e.g.
9393
9494
with StrArray(list_of_strings) as arr:
95-
C.git_function_that_takes_strarray(arr)
95+
C.git_function_that_takes_strarray(arr.ptr)
9696
"""
9797

9898
def __init__(self, l):
@@ -117,11 +117,15 @@ def __init__(self, l):
117117
self.array = ffi.new('git_strarray *', [self._arr, len(strings)])
118118

119119
def __enter__(self):
120-
return self.array
120+
return self
121121

122122
def __exit__(self, type, value, traceback):
123123
pass
124124

125+
@property
126+
def ptr(self):
127+
return self.array
128+
125129

126130
class GenericIterator:
127131
"""Helper to easily implement an iterator.

0 commit comments

Comments
 (0)