1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
hgapi
=====
.. image:: https://travis-ci.org/haard/hgapi.png?branch=master
:target: https://travis-ci.org/haard/hgapi
hgapi is a pure-Python API to Mercurial, that uses the command-line
interface instead of the internal Mercurial API. The rationale for
this is twofold: the internal API is unstable, and it is GPL.
hgapi works for all versions of Mercurial, and will instantly reflect any
changes to the repository (including hgrc). It also has a really
permissive license (do whatever you want, don't blame me).
For example of code that uses this API, take a look at
https://bitbucket.org/haard/autohook which now uses hgapi
exclusively. Add any feature requests or bugs found to the issue tracker.
So far, the API supports::
hg add [<file>]
hg addremove [<file>]
hg archive [-t type] [-r rev] <destination>
hg bookmarks [-r rev] [-f] [-m name newname | -d name | -i name | name]
hg branch
hg branches
hg clone
hg commit [files] [-u name] [--close-branch]
hg diff
hg heads
hg id
hg incoming
hg init
hg log
hg merge (fails on conflict)
hg outgoing
hg paths
hg pull [<source>]
hg push [<destination>]
hg remove
hg rename <source> <destination>
hg revert
hg root
hg status
hg tag
hg tags
hg update <rev>
hg version
You also have access to the configuration (config, configbool,
configlist) just as in the internal Mercurial API. The repository
supports slicing and indexing notation.
Example usage::
>>> import hgapi
>>> repo = hgapi.Repo("test_hgapi") # existing folder
>>> repo.hg_init()
>>> repo.hg_add("file.txt") # already created but not added file
>>> repo.hg_commit("Adding file.txt", user="me")
>>> str(repo['tip'].desc)
'Adding file.txt'
>>> len(repo[0:'tip'])
1
>>> open('test_hgapi/file.txt', 'a').write('\nAdded line') # doctest: +IGNORE_RESULT
>>> diff = repo.hg_diff() # returns list of diffs
>>> assert diff[0]['filename'] == 'file.txt'
>>> assert '+Added line' in diff[0]['diff']
Installation
============
Easiest is easy_install or pip from PyPy::
pip install hgapi
or::
easy_install hgapi
Otherwise, download the source, make sure you have setuptools
installed, and then run::
python setup.py install
Development
===========
Do not hesitate to send requests, issues or perform code reviews! When developing please follow the pep8 guidelines (see http://legacy.python.org/dev/peps/pep-0008/) and do use tox to check your code::
tox
Tox will make sure that hgapi runs on Python 2.7, 3.2, 3.3 and 3.4; and it will check the pep8 compliance.
By contributing you agree to release the code under the license terms listed below (basically - anyone can do anything with this code). Feel free to add yourself to the contributor list in your pull request.
Contributors
============
* Fredrik Håård
* Jan Willems
* Stephen Paulger
* Andy Tang
* Thomas Röggla
* Ardo Illaste
* Ken Cochrane
* Simon Williams
License
=======
Copyright (c) 2011, Fredrik Håård
Do whatever you want, don't blame me. You may also use this software
as licensed under the MIT or BSD licenses, or the more permissive license below:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|