| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,8 @@ New BSD License. See the LICENSE file. | |||
| 74 | 74 | [](https://travis-ci.org/gitpython-developers/GitPython) | |
| 75 | 75 | [](https://coveralls.io/r/gitpython-developers/GitPython?branch=master) | |
| 76 | 76 | [](https://readthedocs.org/projects/gitpython/?badge=stable) | |
| 77 | + [](http://www.issuestats.com/github/gitpython-developers/GitPython) | ||
| 78 | + [](http://www.issuestats.com/github/gitpython-developers/GitPython) | ||
| 77 | 79 | ||
| 78 | 80 | Now that there seems to be a massive user base, this should be motivation enough to let git-python return to a proper state, which means | |
| 79 | 81 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,13 +17,15 @@ Objects.Blob | |||
| 17 | 17 | .. automodule:: git.objects.blob | |
| 18 | 18 | :members: | |
| 19 | 19 | :undoc-members: | |
| 20 | + :special-members: | ||
| 20 | 21 | ||
| 21 | 22 | Objects.Commit | |
| 22 | 23 | -------------- | |
| 23 | 24 | ||
| 24 | 25 | .. automodule:: git.objects.commit | |
| 25 | 26 | :members: | |
| 26 | 27 | :undoc-members: | |
| 28 | + :special-members: | ||
| 27 | 29 | ||
| 28 | 30 | Objects.Tag | |
| 29 | 31 | ----------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,26 +55,67 @@ Archive the repository contents to a tar file. | |||
| 55 | 55 | :start-after: # [6-test_init_repo_object] | |
| 56 | 56 | :end-before: # ![6-test_init_repo_object] | |
| 57 | 57 | ||
| 58 | - .. todo repo paths, heads, remotes, submodules | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - Object Databases | ||
| 62 | - **************** | ||
| 63 | - ``Repo`` instances are powered by its object database instance which will be used when extracting any data, or when writing new objects. | ||
| 58 | + Advanced Repo Usage | ||
| 59 | + =================== | ||
| 64 | 60 | ||
| 65 | - The type of the database determines certain performance characteristics, such as the quantity of objects that can be read per second, the resource usage when reading large data files, as well as the average memory footprint of your application. | ||
| 61 | + And of course, there is much more you can do with this type, most of the following will be explained in greater detail in specific tutorials. | ||
| 66 | 62 | ||
| 67 | - GitDB | ||
| 68 | - ===== | ||
| 69 | - The GitDB is a pure-python implementation of the git object database. It is the default database to use in GitPython 0.3. Its uses less memory when handling huge files, but will be 2 to 5 times slower when extracting large quantities small of objects from densely packed repositories:: | ||
| 70 | - | ||
| 71 | - repo = Repo("path/to/repo", odbt=GitDB) | ||
| 63 | + Query relevant repository paths ... | ||
| 64 | + | ||
| 65 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 66 | + :language: python | ||
| 67 | + :start-after: # [7-test_init_repo_object] | ||
| 68 | + :end-before: # ![7-test_init_repo_object] | ||
| 69 | + | ||
| 70 | + :class:`Heads <git.refs.head.Head>` Heads are branches in git-speak. :class:`References <git.refs.reference.Reference>` are pointers to a specific commit or to other references. Heads and :class:`Tags <git.refs.tag.TagReference>` are a kind of references. GitPython allows you to query them rather intuitively. | ||
| 71 | + | ||
| 72 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 73 | + :language: python | ||
| 74 | + :start-after: # [8-test_init_repo_object] | ||
| 75 | + :end-before: # ![8-test_init_repo_object] | ||
| 76 | + | ||
| 77 | + You can also create new heads ... | ||
| 78 | + | ||
| 79 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 80 | + :language: python | ||
| 81 | + :start-after: # [9-test_init_repo_object] | ||
| 82 | + :end-before: # ![9-test_init_repo_object] | ||
| 83 | + | ||
| 84 | + ... and tags ... | ||
| 85 | + | ||
| 86 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 87 | + :language: python | ||
| 88 | + :start-after: # [10-test_init_repo_object] | ||
| 89 | + :end-before: # ![10-test_init_repo_object] | ||
| 90 | + | ||
| 91 | + You can traverse down to :class:`git objects <git.objects.base.Object>` through references and other objects. Some objects like :class:`commits <git.objects.commit.Commit>` have additional meta-data to query. | ||
| 92 | + | ||
| 93 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 94 | + :language: python | ||
| 95 | + :start-after: # [11-test_init_repo_object] | ||
| 96 | + :end-before: # ![11-test_init_repo_object] | ||
| 97 | + | ||
| 98 | + :class:`Remotes <git.remote.Remote>` allow to handle fetch, pull and push operations, while providing optional real-time progress information to :class:`progress delegates <git.util.RemoteProgress>`. | ||
| 99 | + | ||
| 100 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 101 | + :language: python | ||
| 102 | + :start-after: # [12-test_init_repo_object] | ||
| 103 | + :end-before: # ![12-test_init_repo_object] | ||
| 104 | + | ||
| 105 | + The :class:`index <git.index.base.IndexFile>` is also called stage in git-speak. It is used to prepare new commits, and can be used to keep results of merge operations. Our index implementation allows to stream date into the index, which is useful for bare repositories that do not have a working tree. | ||
| 106 | + | ||
| 107 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 108 | + :language: python | ||
| 109 | + :start-after: # [13-test_init_repo_object] | ||
| 110 | + :end-before: # ![13-test_init_repo_object] | ||
| 111 | + | ||
| 112 | + :class:`Submodules <git.objects.submodule.Submodule>` represent all aspects of git submodules, which allows you query all of their related information, and manipulate in various ways. | ||
| 113 | + | ||
| 114 | + .. literalinclude:: ../../git/test/test_docs.py | ||
| 115 | + :language: python | ||
| 116 | + :start-after: # [14-test_init_repo_object] | ||
| 117 | + :end-before: # ![14-test_init_repo_object] | ||
| 72 | 118 | ||
| 73 | - GitCmdObjectDB | ||
| 74 | - ============== | ||
| 75 | - The git command database uses persistent git-cat-file instances to read repository information. These operate very fast under all conditions, but will consume additional memory for the process itself. When extracting large files, memory usage will be much higher than the one of the ``GitDB``:: | ||
| 76 | - | ||
| 77 | - repo = Repo("path/to/repo", odbt=GitCmdObjectDB) | ||
| 78 | 119 | ||
| 79 | 120 | Examining References | |
| 80 | 121 | ******************** | |
@@ -107,7 +148,7 @@ Access the reflog easily:: | |||
| 107 | 148 | log[0] # first (i.e. oldest) reflog entry | |
| 108 | 149 | log[-1] # last (i.e. most recent) reflog entry | |
| 109 | 150 | ||
| 110 | - For more information on the reflog, see the ``RefLog`` type's documentation. | ||
| 151 | + For more information on the reflog, see the :class:`git.RefLog <git.refs.log.RefLog>` type's documentation. | ||
| 111 | 152 | ||
| 112 | 153 | Modifying References | |
| 113 | 154 | ******************** | |
@@ -454,6 +495,26 @@ The special notion ``git.command(flag=True)`` will create a flag without value l | |||
| 454 | 495 | ||
| 455 | 496 | If ``None`` is found in the arguments, it will be dropped silently. Lists and tuples passed as arguments will be unpacked recursively to individual arguments. Objects are converted to strings using the str(...) function. | |
| 456 | 497 | ||
| 498 | + | ||
| 499 | + Object Databases | ||
| 500 | + **************** | ||
| 501 | + :class:`git.Repo <git.repo.base.Repo>` instances are powered by its object database instance which will be used when extracting any data, or when writing new objects. | ||
| 502 | + | ||
| 503 | + The type of the database determines certain performance characteristics, such as the quantity of objects that can be read per second, the resource usage when reading large data files, as well as the average memory footprint of your application. | ||
| 504 | + | ||
| 505 | + GitDB | ||
| 506 | + ===== | ||
| 507 | + The GitDB is a pure-python implementation of the git object database. It is the default database to use in GitPython 0.3. Its uses less memory when handling huge files, but will be 2 to 5 times slower when extracting large quantities small of objects from densely packed repositories:: | ||
| 508 | + | ||
| 509 | + repo = Repo("path/to/repo", odbt=GitDB) | ||
| 510 | + | ||
| 511 | + | ||
| 512 | + GitCmdObjectDB | ||
| 513 | + ============== | ||
| 514 | + The git command database uses persistent git-cat-file instances to read repository information. These operate very fast under all conditions, but will consume additional memory for the process itself. When extracting large files, memory usage will be much higher than the one of the ``GitDB``:: | ||
| 515 | + | ||
| 516 | + repo = Repo("path/to/repo", odbt=GitCmdObjectDB) | ||
| 517 | + | ||
| 457 | 518 | Git Command Debugging and Customization | |
| 458 | 519 | *************************************** | |
| 459 | 520 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -579,11 +579,16 @@ def execute(self, command, | |||
| 579 | 579 | ||
| 580 | 580 | if self.GIT_PYTHON_TRACE == 'full': | |
| 581 | 581 | cmdstr = " ".join(command) | |
| 582 | + | ||
| 583 | + def as_text(stdout_value): | ||
| 584 | + return not output_stream and stdout_value.decode(defenc) or '<OUTPUT_STREAM>' | ||
| 585 | + # end | ||
| 586 | + | ||
| 582 | 587 | if stderr_value: | |
| 583 | 588 | log.info("%s -> %d; stdout: '%s'; stderr: '%s'", | |
| 584 | - cmdstr, status, stdout_value.decode(defenc), stderr_value.decode(defenc)) | ||
| 589 | + cmdstr, status, as_text(stdout_value), stderr_value.decode(defenc)) | ||
| 585 | 590 | elif stdout_value: | |
| 586 | - log.info("%s -> %d; stdout: '%s'", cmdstr, status, stdout_value.decode(defenc)) | ||
| 591 | + log.info("%s -> %d; stdout: '%s'", cmdstr, status, as_text(stdout_value)) | ||
| 587 | 592 | else: | |
| 588 | 593 | log.info("%s -> %d", cmdstr, status) | |
| 589 | 594 | # END handle debug printing | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,7 +135,7 @@ def __init__(self, repo, binsha, mode=None, path=None): | |||
| 135 | 135 | ||
| 136 | 136 | :param repo: is the Repo we are located in | |
| 137 | 137 | :param binsha: 20 byte sha1 | |
| 138 | - :param mode: | ||
| 138 | + :param mode: | ||
| 139 | 139 | is the stat compatible file mode as int, use the stat module | |
| 140 | 140 | to evaluate the infomration | |
| 141 | 141 | :param path: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut | |||
| 69 | 69 | message=None, parents=None, encoding=None, gpgsig=None): | |
| 70 | 70 | """Instantiate a new Commit. All keyword arguments taking None as default will | |
| 71 | 71 | be implicitly set on first query. | |
| 72 | + | ||
| 72 | 73 | :param binsha: 20 byte sha1 | |
| 73 | 74 | :param parents: tuple( Commit, ... ) | |
| 74 | 75 | is a tuple of commit ids or actual Commits | |
@@ -97,7 +98,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut | |||
| 97 | 98 | dependency graph | |
| 98 | 99 | :return: git.Commit | |
| 99 | 100 | ||
| 100 | - :note: Timezone information is in the same format and in the same sign | ||
| 101 | + :note: | ||
| 102 | + Timezone information is in the same format and in the same sign | ||
| 101 | 103 | as what time.altzone returns. The sign is inverted compared to git's | |
| 102 | 104 | UTC timezone.""" | |
| 103 | 105 | super(Commit, self).__init__(repo, binsha) | |
@@ -296,6 +298,11 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, | |||
| 296 | 298 | # empty repositories have no head commit | |
| 297 | 299 | parent_commits = list() | |
| 298 | 300 | # END handle parent commits | |
| 301 | + else: | ||
| 302 | + for p in parent_commits: | ||
| 303 | + if not isinstance(p, cls): | ||
| 304 | + raise ValueError("Parent commit '%r' must be of type %s" % (p, cls)) | ||
| 305 | + # end check parent commit types | ||
| 299 | 306 | # END if parent commits are unset | |
| 300 | 307 | ||
| 301 | 308 | # retrieve all additional information, create a commit object, and | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -781,7 +781,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): | |||
| 781 | 781 | csm.remove(module, force, configuration, dry_run) | |
| 782 | 782 | del(csm) | |
| 783 | 783 | # end | |
| 784 | - if not dry_run and nc > 0: | ||
| 784 | + if configuration and not dry_run and nc > 0: | ||
| 785 | 785 | # Assure we don't leave the parent repository in a dirty state, and commit our changes | |
| 786 | 786 | # It's important for recursive, unforced, deletions to work as expected | |
| 787 | 787 | self.module().index.commit("Removed submodule '%s'" % self.name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,8 @@ def __str__(self): | |||
| 51 | 51 | #{ Interface | |
| 52 | 52 | ||
| 53 | 53 | def set_object(self, object, logmsg=None): | |
| 54 | - """Special version which checks if the head-log needs an update as well""" | ||
| 54 | + """Special version which checks if the head-log needs an update as well | ||
| 55 | + :return: self""" | ||
| 55 | 56 | oldbinsha = None | |
| 56 | 57 | if logmsg is not None: | |
| 57 | 58 | head = self.repo.head | |
@@ -78,6 +79,8 @@ def set_object(self, object, logmsg=None): | |||
| 78 | 79 | self.repo.head.log_append(oldbinsha, logmsg) | |
| 79 | 80 | # END check if the head | |
| 80 | 81 | ||
| 82 | + return self | ||
| 83 | + | ||
| 81 | 84 | # NOTE: Don't have to overwrite properties as the will only work without a the log | |
| 82 | 85 | ||
| 83 | 86 | @property | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -378,6 +378,8 @@ def _config_section_name(self): | |||
| 378 | 378 | ||
| 379 | 379 | def _set_cache_(self, attr): | |
| 380 | 380 | if attr == "_config_reader": | |
| 381 | + # NOTE: This is cached as __getattr__ is overridden to return remote config values implicitly, such as | ||
| 382 | + # in print(r.pushurl) | ||
| 381 | 383 | self._config_reader = SectionConstraint(self.repo.config_reader(), self._config_section_name()) | |
| 382 | 384 | else: | |
| 383 | 385 | super(Remote, self)._set_cache_(attr) | |
@@ -475,8 +477,13 @@ def create(cls, repo, name, url, **kwargs): | |||
| 475 | 477 | ||
| 476 | 478 | @classmethod | |
| 477 | 479 | def remove(cls, repo, name): | |
| 478 | - """Remove the remote with the given name""" | ||
| 480 | + """Remove the remote with the given name | ||
| 481 | + :return: the passed remote name to remove | ||
| 482 | + """ | ||
| 479 | 483 | repo.git.remote("rm", name) | |
| 484 | + if isinstance(name, cls): | ||
| 485 | + name._clear_cache() | ||
| 486 | + return name | ||
| 480 | 487 | ||
| 481 | 488 | # alias | |
| 482 | 489 | rm = remove | |
@@ -489,11 +496,8 @@ def rename(self, new_name): | |||
| 489 | 496 | ||
| 490 | 497 | self.repo.git.remote("rename", self.name, new_name) | |
| 491 | 498 | self.name = new_name | |
| 492 | - try: | ||
| 493 | - del(self._config_reader) # it contains cached values, section names are different now | ||
| 494 | - except AttributeError: | ||
| 495 | - pass | ||
| 496 | - # END handle exception | ||
| 499 | + self._clear_cache() | ||
| 500 | + | ||
| 497 | 501 | return self | |
| 498 | 502 | ||
| 499 | 503 | def update(self, **kwargs): | |
@@ -662,6 +666,13 @@ def config_reader(self): | |||
| 662 | 666 | Hence you may simple type config.get("pushurl") to obtain the information""" | |
| 663 | 667 | return self._config_reader | |
| 664 | 668 | ||
| 669 | + def _clear_cache(self): | ||
| 670 | + try: | ||
| 671 | + del(self._config_reader) | ||
| 672 | + except AttributeError: | ||
| 673 | + pass | ||
| 674 | + # END handle exception | ||
| 675 | + | ||
| 665 | 676 | @property | |
| 666 | 677 | def config_writer(self): | |
| 667 | 678 | """ | |
@@ -676,9 +687,5 @@ def config_writer(self): | |||
| 676 | 687 | writer = self.repo.config_writer() | |
| 677 | 688 | ||
| 678 | 689 | # clear our cache to assure we re-read the possibly changed configuration | |
| 679 | - try: | ||
| 680 | - del(self._config_reader) | ||
| 681 | - except AttributeError: | ||
| 682 | - pass | ||
| 683 | - # END handle exception | ||
| 690 | + self._clear_cache() | ||
| 684 | 691 | return SectionConstraint(writer, self._config_section_name()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,10 +209,8 @@ def _set_description(self, descr): | |||
| 209 | 209 | ||
| 210 | 210 | @property | |
| 211 | 211 | def working_tree_dir(self): | |
| 212 | - """:return: The working tree directory of our git repository | ||
| 213 | - :raise AssertionError: If we are a bare repository""" | ||
| 214 | - if self._working_tree_dir is None: | ||
| 215 | - raise AssertionError("Repository at %r is bare and does not have a working tree directory" % self.git_dir) | ||
| 212 | + """:return: The working tree directory of our git repository. If this is a bare repository, None is returned. | ||
| 213 | + """ | ||
| 216 | 214 | return self._working_tree_dir | |
| 217 | 215 | ||
| 218 | 216 | @property | |
| Back | FazBrowse Home | New Git URL |
0 commit comments