Skip to content

Commit a022f1f

Browse files
authored
docs updated and support for default branches (#19)
1 parent cffcadc commit a022f1f

File tree

8 files changed

+462
-264
lines changed

8 files changed

+462
-264
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v2.2.0
2+
======
3+
4+
* Support for default branch setting instead of assuming master, will infer if not passed
5+
* Better handling of ignore repos in project directory setup
6+
* Added a branch exists helper in repository
7+
* Docs corrections
8+
19
v2.1.0
210
======
311

docs/source/cache.rst

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,88 @@ The caching system provides:
1111
* Redis-based caching for persistent storage
1212
* Configurable cache durations
1313
* Automatic cache invalidation
14+
* Decorator-based caching for expensive operations
1415

1516
Available Cache Backends
1617
----------------------
1718

18-
In-Memory Cache
19-
~~~~~~~~~~~~~
19+
In-Memory Cache (EphemeralCache)
20+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021

2122
The default in-memory cache is ephemeral and will be cleared when the process ends:
2223

2324
.. code-block:: python
2425
2526
from gitpandas import Repository
26-
repo = Repository('/path/to/repo', cache=True) # Enable in-memory caching
27-
28-
Redis Cache
29-
~~~~~~~~~
27+
from gitpandas.cache import EphemeralCache
28+
29+
# Create an in-memory cache with default settings
30+
cache = EphemeralCache()
31+
32+
# Or customize the cache size
33+
cache = EphemeralCache(max_keys=500)
34+
35+
# Use the cache with a repository
36+
repo = Repository('/path/to/repo', cache_backend=cache)
37+
38+
Redis Cache (RedisDFCache)
39+
~~~~~~~~~~~~~~~~~~~~~~~
3040

3141
For persistent caching across sessions, use Redis:
3242

3343
.. code-block:: python
3444
3545
from gitpandas import Repository
36-
repo = Repository(
37-
'/path/to/repo',
38-
cache=True,
39-
cache_backend='redis',
40-
redis_url='redis://localhost:6379/0'
46+
from gitpandas.cache import RedisDFCache
47+
48+
# Create a Redis cache with default settings
49+
cache = RedisDFCache()
50+
51+
# Or customize Redis connection and cache settings
52+
cache = RedisDFCache(
53+
host='localhost',
54+
port=6379,
55+
db=12,
56+
max_keys=1000,
57+
ttl=3600 # Cache entries expire after 1 hour
58+
)
59+
60+
# Use the cache with a repository
61+
repo = Repository('/path/to/repo', cache_backend=cache)
62+
63+
Using the Cache Decorator
64+
----------------------
65+
66+
The `@multicache` decorator can be used to cache method results:
67+
68+
.. code-block:: python
69+
70+
from gitpandas.cache import multicache
71+
72+
@multicache(
73+
key_prefix="method_name",
74+
key_list=["param1", "param2"],
75+
skip_if=lambda x: x.get("param1") is None
4176
)
77+
def expensive_method(self, param1, param2):
78+
# Method implementation
79+
pass
4280
4381
Configuration
4482
------------
4583

46-
You can configure cache behavior through the following parameters:
84+
Cache backends can be configured with various parameters:
4785

48-
* ``cache``: Enable/disable caching (default: False)
49-
* ``cache_backend``: Choose the cache backend ('memory' or 'redis')
50-
* ``cache_ttl``: Time-to-live for cached results in seconds
86+
EphemeralCache:
87+
* ``max_keys``: Maximum number of keys to store in memory (default: 1000)
88+
89+
RedisDFCache:
90+
* ``host``: Redis host (default: 'localhost')
91+
* ``port``: Redis port (default: 6379)
92+
* ``db``: Redis database number (default: 12)
93+
* ``max_keys``: Maximum number of keys to store (default: 1000)
94+
* ``ttl``: Time-to-live in seconds for cache entries (default: None, no expiration)
95+
* Additional keyword arguments are passed to redis.StrictRedis
5196

5297
API Reference
5398
------------
@@ -59,16 +104,18 @@ API Reference
59104
:undoc-members:
60105
:show-inheritance:
61106
:inherited-members:
62-
:special-members: __init__, __getitem__, __setitem__, __delitem__
107+
:special-members: __init__, __getitem__, __setitem__, __delitem__, __contains__, __len__
63108

64-
.. autoclass:: MemoryCache
109+
.. autoclass:: EphemeralCache
65110
:members:
66111
:undoc-members:
67112
:show-inheritance:
68113
:inherited-members:
69114

70-
.. autoclass:: RedisCache
115+
.. autoclass:: RedisDFCache
71116
:members:
72117
:undoc-members:
73118
:show-inheritance:
74119
:inherited-members:
120+
121+
.. autofunction:: multicache

docs/source/project.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ Create a ProjectDirectory from a directory containing multiple repositories:
2626
.. code-block:: python
2727
2828
from gitpandas import ProjectDirectory
29-
project = ProjectDirectory(working_dir='/path/to/dir/', ignore=None, verbose=True)
29+
project = ProjectDirectory(
30+
working_dir='/path/to/dir/',
31+
ignore_repos=['repo_to_ignore'],
32+
verbose=True,
33+
default_branch='main' # Optional, will auto-detect if not specified
34+
)
3035
31-
The `ignore` parameter can be a list of directories to exclude. This method uses `os.walk` to search for `.git` directories recursively.
36+
The `ignore_repos` parameter can be a list of repository names to exclude. This method uses `os.walk` to search for `.git` directories recursively.
3237

3338
To check which repositories are included:
3439

3540
.. code-block:: python
3641
37-
print(project._repo_name())
42+
print(project.repo_name())
3843
3944
Explicit Local Repositories
4045
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -46,8 +51,9 @@ Create a ProjectDirectory from a list of local repositories:
4651
from gitpandas import ProjectDirectory
4752
project = ProjectDirectory(
4853
working_dir=['/path/to/repo1/', '/path/to/repo2/'],
49-
ignore=None,
50-
verbose=True
54+
ignore_repos=['repo_to_ignore'],
55+
verbose=True,
56+
default_branch='main' # Optional, will auto-detect if not specified
5157
)
5258
5359
Explicit Remote Repositories
@@ -60,8 +66,9 @@ Create a ProjectDirectory from a list of remote repositories:
6066
from gitpandas import ProjectDirectory
6167
project = ProjectDirectory(
6268
working_dir=['git://github.com/user/repo1.git', 'git://github.com/user/repo2.git'],
63-
ignore=None,
64-
verbose=True
69+
ignore_repos=['repo_to_ignore'],
70+
verbose=True,
71+
default_branch='main' # Optional, will auto-detect if not specified
6572
)
6673
6774
Common Operations
@@ -72,7 +79,7 @@ Here are some common operations you can perform with a ProjectDirectory object:
7279
.. code-block:: python
7380
7481
# Get commit history across all repositories
75-
commits_df = project.commit_history(branch='master')
82+
commits_df = project.commit_history()
7683
7784
# Get blame information across all repositories
7885
blame_df = project.blame()
@@ -85,6 +92,9 @@ Here are some common operations you can perform with a ProjectDirectory object:
8592
8693
# Get file change history across all repositories
8794
changes_df = project.file_change_history()
95+
96+
# Get detailed repository information
97+
repo_info = project.repo_information()
8898
8999
API Reference
90100
------------
@@ -110,11 +120,5 @@ API Reference
110120
~ProjectDirectory.tags
111121
~ProjectDirectory.revs
112122
~ProjectDirectory.bus_factor
113-
~ProjectDirectory.is_bare
114-
~ProjectDirectory.has_coverage
115-
116-
.. rubric:: Properties
117-
118-
.. autosummary::
119-
:nosignatures:
123+
~ProjectDirectory.repo_information
120124
~ProjectDirectory.repo_name

docs/source/repository.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ Create a Repository from a local Git repository:
2626
.. code-block:: python
2727
2828
from gitpandas import Repository
29-
repo = Repository(working_dir='/path/to/repo/', verbose=True)
29+
repo = Repository(
30+
working_dir='/path/to/repo/',
31+
verbose=True,
32+
default_branch='main' # Optional, will auto-detect if not specified
33+
)
3034
3135
The directory must contain a `.git` directory. Subdirectories are not searched.
3236

@@ -38,7 +42,11 @@ Create a Repository from a remote Git repository:
3842
.. code-block:: python
3943
4044
from gitpandas import Repository
41-
repo = Repository(working_dir='git://github.com/user/repo.git', verbose=True)
45+
repo = Repository(
46+
working_dir='git://github.com/user/repo.git',
47+
verbose=True,
48+
default_branch='main' # Optional, will auto-detect if not specified
49+
)
4250
4351
The repository will be cloned locally into a temporary directory. This can be slow for large repositories.
4452

@@ -63,6 +71,9 @@ Here are some common operations you can perform with a Repository object:
6371
6472
# Get file change history
6573
changes_df = repo.file_change_history()
74+
75+
# Get repository name
76+
repo_name = repo.repo_name
6677
6778
API Reference
6879
------------
@@ -90,12 +101,16 @@ API Reference
90101
~Repository.bus_factor
91102
~Repository.is_bare
92103
~Repository.has_coverage
104+
~Repository.has_branch
105+
~Repository.get_branches_by_commit
106+
~Repository.commits_in_tags
93107

94108
.. rubric:: Properties
95109

96110
.. autosummary::
97111
:nosignatures:
98112
~Repository.repo_name
113+
~Repository.default_branch
99114

100115
.. autoclass:: GitFlowRepository
101116
:members:

0 commit comments

Comments
 (0)