Skip to content

Commit cd26aae

Browse files
committed
Made repository paths methods a property to be compatible with the existing repo interface. Added submodule interface ... goal is to provide all of the extra repo functionality in custom interfaces
1 parent 7ae36c3 commit cd26aae

File tree

14 files changed

+234
-80
lines changed

14 files changed

+234
-80
lines changed

git/db/compat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5+
"""Module providing adaptors to maintain backwards compatability"""
6+
7+
class RepoCompatInterface(object):
8+
"""Interface to install backwards compatability of the new complex repository
9+
types with the previous, all in one, repository."""
10+
11+
@property
12+
def bare(self):
13+
return self.is_bare

git/db/interface.py

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
__all__ = ( 'ObjectDBR', 'ObjectDBW', 'RootPathDB', 'CompoundDB', 'CachingDB',
88
'TransportDB', 'ConfigurationMixin', 'RepositoryPathsMixin',
9-
'RefSpec', 'FetchInfo', 'PushInfo', 'ReferencesMixin')
9+
'RefSpec', 'FetchInfo', 'PushInfo', 'ReferencesMixin', 'SubmoduleDB')
1010

1111

1212
class ObjectDBR(object):
@@ -151,7 +151,7 @@ def __init__(self, root_path):
151151
access."""
152152
super(RootPathDB, self).__init__(root_path)
153153

154-
#{ Interface
154+
#{ Interface
155155
def root_path(self):
156156
""":return: path at which this db operates"""
157157
raise NotImplementedError()
@@ -390,33 +390,60 @@ def _initialize(self, path):
390390
raise NotImplementedError()
391391
#} end subclass interface
392392

393+
#{ Object Interface
394+
395+
def __eq__(self, rhs):
396+
raise NotImplementedError()
397+
398+
def __ne__(self, rhs):
399+
raise NotImplementedError()
400+
401+
def __hash__(self):
402+
raise NotImplementedError()
403+
404+
def __repr__(self):
405+
raise NotImplementedError()
406+
407+
#} END object interface
408+
393409
#{ Interface
394410

411+
@property
395412
def is_bare(self):
396413
""":return: True if this is a bare repository
397414
:note: this value is cached upon initialization"""
398415
raise NotImplementedError()
399416

400-
def git_path(self):
417+
@property
418+
def git_dir(self):
401419
""":return: path to directory containing this actual git repository (which
402420
in turn provides access to objects and references"""
403421
raise NotImplementedError()
404422

405-
def working_tree_path(self):
423+
@property
424+
def working_tree_dir(self):
406425
""":return: path to directory containing the working tree checkout of our
407426
git repository.
408427
:raise AssertionError: If this is a bare repository"""
409428
raise NotImplementedError()
410429

411-
def objects_path(self):
430+
@property
431+
def objects_dir(self):
412432
""":return: path to the repository's objects directory"""
413433
raise NotImplementedError()
414434

435+
@property
415436
def working_dir(self):
416437
""":return: working directory of the git process or related tools, being
417-
either the working_tree_path if available or the git_path"""
438+
either the working_tree_dir if available or the git_path"""
418439
raise NotImplementedError()
419-
440+
441+
@property
442+
def description(self):
443+
""":return: description text associated with this repository or set the
444+
description."""
445+
raise NotImplementedError()
446+
420447
#} END interface
421448

422449

@@ -465,5 +492,43 @@ def config_writer(self, config_level="repository"):
465492
repository = configuration file for this repostory only"""
466493
raise NotImplementedError()
467494

495+
468496
#} END interface
469497

498+
499+
class SubmoduleDB(object):
500+
"""Interface providing access to git repository submodules.
501+
The actual implementation is found in the Submodule object type, which is
502+
currently only available in one implementation."""
503+
504+
@property
505+
def submodules(self):
506+
"""
507+
:return: git.IterableList(Submodule, ...) of direct submodules
508+
available from the current head"""
509+
raise NotImplementedError()
510+
511+
def submodule(self, name):
512+
""" :return: Submodule with the given name
513+
:raise ValueError: If no such submodule exists"""
514+
raise NotImplementedError()
515+
516+
def create_submodule(self, *args, **kwargs):
517+
"""Create a new submodule
518+
519+
:note: See the documentation of Submodule.add for a description of the
520+
applicable parameters
521+
:return: created submodules"""
522+
raise NotImplementedError()
523+
524+
def iter_submodules(self, *args, **kwargs):
525+
"""An iterator yielding Submodule instances, see Traversable interface
526+
for a description of args and kwargs
527+
:return: Iterator"""
528+
raise NotImplementedError()
529+
530+
def submodule_update(self, *args, **kwargs):
531+
"""Update the submodules, keeping the repository consistent as it will
532+
take the previous state into consideration. For more information, please
533+
see the documentation of RootModule.update"""
534+
raise NotImplementedError()

git/db/py/base.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,34 +273,70 @@ def _initialize(self, path):
273273
# lets not assume the option exists, although it should
274274
pass
275275
#END check bare flag
276+
277+
#} end subclass interface
278+
279+
#{ Object Interface
280+
281+
def __eq__(self, rhs):
282+
if hasattr(rhs, 'git_dir'):
283+
return self.git_dir == rhs.git_dir
284+
return False
285+
286+
def __ne__(self, rhs):
287+
return not self.__eq__(rhs)
288+
289+
def __hash__(self):
290+
return hash(self.git_dir)
276291

292+
def __repr__(self):
293+
return "%s(%r)" % (type(self).__name__, self.git_dir)
277294

278-
#} end subclass interface
295+
#} END object interface
279296

280297
#{ Interface
281298

299+
@property
282300
def is_bare(self):
283301
return self._bare
284302

285-
def git_path(self):
303+
@property
304+
def git_dir(self):
286305
return self._git_path
287306

288-
def working_tree_path(self):
289-
if self.is_bare():
290-
raise AssertionError("Repository at %s is bare and does not have a working tree directory" % self.git_path())
307+
@property
308+
def working_tree_dir(self):
309+
if self.is_bare:
310+
raise AssertionError("Repository at %s is bare and does not have a working tree directory" % self.git_dir)
291311
#END assertion
292-
return dirname(self.git_path())
293-
294-
def objects_path(self):
295-
return join(self.git_path(), self.objs_dir)
296-
312+
return dirname(self.git_dir)
313+
314+
@property
315+
def objects_dir(self):
316+
return join(self.git_dir, self.objs_dir)
317+
318+
@property
297319
def working_dir(self):
298-
if self.is_bare():
299-
return self.git_path()
320+
if self.is_bare:
321+
return self.git_dir
300322
else:
301-
return self.working_tree_dir()
323+
return self.working_tree_dir
302324
#END handle bare state
303325

326+
def _mk_description():
327+
def _get_description(self):
328+
filename = join(self.git_dir, 'description')
329+
return file(filename).read().rstrip()
330+
331+
def _set_description(self, descr):
332+
filename = join(self.git_dir, 'description')
333+
file(filename, 'w').write(descr+'\n')
334+
335+
return property(_get_description, _set_description, "Descriptive text for the content of the repository")
336+
337+
description = _mk_description()
338+
del(_mk_description)
339+
304340
#} END interface
305341

306342

@@ -313,7 +349,7 @@ class PureConfigurationMixin(ConfigurationMixin):
313349

314350
def __init__(self, *args, **kwargs):
315351
"""Verify prereqs"""
316-
assert hasattr(self, 'git_path')
352+
assert hasattr(self, 'git_dir')
317353

318354
def _path_at_level(self, level ):
319355
# we do not support an absolute path of the gitconfig on windows ,
@@ -327,7 +363,7 @@ def _path_at_level(self, level ):
327363
elif level == "global":
328364
return normpath(expanduser("~/.%s" % self.system_config_file_name))
329365
elif level == "repository":
330-
return join(self.git_path(), self.repo_config_file_name)
366+
return join(self.git_dir, self.repo_config_file_name)
331367
#END handle level
332368

333369
raise ValueError("Invalid configuration level: %r" % level)
@@ -346,5 +382,6 @@ def config_reader(self, config_level=None):
346382
def config_writer(self, config_level="repository"):
347383
return GitConfigParser(self._path_at_level(config_level), read_only=False)
348384

385+
349386
#} END interface
350387

git/db/py/complex.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from loose import PureLooseObjectODB
1616
from pack import PurePackedODB
1717
from ref import PureReferenceDB
18+
from submodule import PureSubmoduleDB
1819

1920
from git.util import (
2021
LazyMixin,
@@ -32,7 +33,7 @@
3233
__all__ = ('PureGitODB', 'PureGitDB')
3334

3435

35-
class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB):
36+
class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB, PureSubmoduleDB):
3637
"""A git-style object-only database, which contains all objects in the 'objects'
3738
subdirectory.
3839
:note: The type needs to be initialized on the ./objects directory to function,
@@ -107,7 +108,7 @@ class PureGitDB(PureGitODB, PureRepositoryPathsMixin, PureConfigurationMixin, Pu
107108
def __init__(self, root_path):
108109
"""Initialize ourselves on the .git directory, or the .git/objects directory."""
109110
PureRepositoryPathsMixin._initialize(self, root_path)
110-
super(PureGitDB, self).__init__(self.objects_path())
111+
super(PureGitDB, self).__init__(self.objects_dir)
111112

112113

113114

git/db/py/submodule.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5+
from git.objects.submodule.base import Submodule
6+
from git.objects.submodule.root import RootModule
7+
from git.db.interface import SubmoduleDB
8+
9+
__all__ = ["PureSubmoduleDB"]
10+
11+
class PureSubmoduleDB(SubmoduleDB):
12+
"""Pure python implementation of submodule functionality"""
13+
14+
@property
15+
def submodules(self):
16+
return Submodule.list_items(self)
17+
18+
def submodule(self, name):
19+
try:
20+
return self.submodules[name]
21+
except IndexError:
22+
raise ValueError("Didn't find submodule named %r" % name)
23+
# END exception handling
24+
25+
def create_submodule(self, *args, **kwargs):
26+
return Submodule.add(self, *args, **kwargs)
27+
28+
def iter_submodules(self, *args, **kwargs):
29+
return RootModule(self).traverse(*args, **kwargs)
30+
31+
def submodule_update(self, *args, **kwargs):
32+
return RootModule(self).update(*args, **kwargs)
33+

git/objects/submodule/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
15
# NOTE: Cannot import anything here as the top-level _init_ has to handle
26
# our dependencies

git/objects/submodule/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
15
from git.util import RepoAliasMixin
26
import util
37
from util import (

git/objects/submodule/root.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
15
from base import Submodule, UpdateProgress
26
from util import (
37
find_first_remote_branch
@@ -24,6 +28,7 @@ class RootUpdateProgress(UpdateProgress):
2428
URLCHANGE = RootUpdateProgress.URLCHANGE
2529
PATHCHANGE = RootUpdateProgress.PATHCHANGE
2630

31+
2732
class RootModule(Submodule):
2833
"""A (virtual) Root of all submodules in the given repository. It can be used
2934
to more easily traverse all submodules of the master repository"""

git/objects/submodule/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
15
import git
26
from git.exc import InvalidGitRepositoryError
37
from git.config import GitConfigParser

git/refs/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def path(cls, ref):
151151
instance would be found. The path is not guaranteed to point to a valid
152152
file though.
153153
:param ref: SymbolicReference instance"""
154-
return join(ref.repo.git_path(), "logs", to_native_path(ref.path))
154+
return join(ref.repo.git_dir, "logs", to_native_path(ref.path))
155155

156156
@classmethod
157157
def iter_entries(cls, stream):

0 commit comments

Comments
 (0)