Skip to content

Change refspec api - #290

Merged
jdavid merged 5 commits into
libgit2:masterfrom
jplana:change_refspec_api
Dec 2, 2013
Merged

jdavid merged 5 commits into
libgit2:masterfrom
jplana:change_refspec_api

Conversation

@jplana

@jplana jplana commented Nov 25, 2013

Copy link
Copy Markdown
Contributor

New attempt to provide refspec API with pygit, now using the new functions in libgit 0.20

It will expose:

the attributes

  • fetch_refspecs
  • push_refspecs

returning a list of strings with the refspecs

the methods

  • set_fetch_refspecs([str])
  • set_push_refspecs([str])

setting a list of strings a new refspecs

Comment thread src/remote.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to_unicode for this which works across verisions.

@jdavid

jdavid commented Nov 25, 2013

Copy link
Copy Markdown
Member

I think the API will be more intuitive if using a getset instead of a method, so:

refspecs = remote.fetch_refspecs
remote.fetch_refspecs = refspecs

Please update the documentation: docs/remotes.rst

Thanks!

@jplana

jplana commented Nov 26, 2013

Copy link
Copy Markdown
Contributor Author

I fixed most of the issues here, except probably the most important, the API. I see one problem with your proposal, while this would work:

remote.fetch_refspecs = ['xxx:xxxx','yyyy:zzzz']

This would not produce the expected result:

remote.fetch_refspecs[0] = 'xxxx:xxxx'

which a user of the library might use, as this is correct:

print remote.fetch_refspecs[0]
>>> 'xxxx:xxxx' 

IMHO a list where you could do

remote.fetch_refspecs[0] = 'xxxx:xxx'
# or even
remote.fetch_refspec.append('xxxx:xxxx')
remove.fetch_refspec.remove('yyyy:yyyy')

would be nicer, though I would leave it for a future PR (comments on this are welcome)

BTW I don't know if the attribute get_refspec makes sense anymore as the user can just "iterate" all refspecs using the refspec_count total but won't know if it's either a push or fetch refspec, not very useful.

@jdavid

jdavid commented Nov 26, 2013

Copy link
Copy Markdown
Member

Then it should be Remote.get_fetch_refspecs() so the API is symmetric.

@jplana

jplana commented Dec 2, 2013

Copy link
Copy Markdown
Contributor Author

I think that fixes all the comments, adding better error treatment and making the API symmetric.

@jdavid

jdavid commented Dec 2, 2013

Copy link
Copy Markdown
Member

After merging I get this error:

$ python setup.py build
[...]
x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/local/include -Iinclude -I/usr/include/python2.7 -c src/remote.c -o build/temp.linux-x86_64-2.7/src/remote.o
src/remote.c: In function ‘Remote_set_fetch_refspecs’:
src/remote.c:503:1: error: expected declaration or statement at end of input
error: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1
@jplana

jplana commented Dec 2, 2013

Copy link
Copy Markdown
Contributor Author

Upssss. Sorry about it.

@jdavid
jdavid merged commit 6050ae0 into libgit2:master Dec 2, 2013
@jplana

jplana commented Dec 2, 2013

Copy link
Copy Markdown
Contributor Author

Thanks a lot for your patience :-D

@jdavid

jdavid commented Dec 2, 2013

Copy link
Copy Markdown
Member

Thank you for contributing.

Note I have fixed error handling. The Python functions already set an exception whenever there is an error, so you only need to set the exception for anything else.

@jplana

jplana commented Dec 3, 2013

Copy link
Copy Markdown
Contributor Author

I see the changes, thanks a lot. Still learning how to do proper python exceptions :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants