Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e263b8

Browse files
committed
Add method to retrieve all possible paths to include
1 parentd5262ac commit8e263b8

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

‎git/config.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
importlogging
1414
importos
1515
importre
16+
importglob
17+
importfnmatch
1618
fromcollectionsimportOrderedDict
1719

1820
fromgit.compatimport (
@@ -455,6 +457,39 @@ def _has_includes(self):
455457
forsectioninself.sections()
456458
)
457459

460+
def_included_paths(self):
461+
"""Return all paths that must be included to configuration.
462+
"""
463+
paths= []
464+
465+
forsectioninself.sections():
466+
ifsection=="include":
467+
paths+=self.items(section)
468+
469+
match=CONDITIONAL_INCLUDE_REGEXP.search(section)
470+
ifmatchisnotNoneandself._repoisnotNone:
471+
keyword=match.group(1)
472+
value=match.group(2).strip()
473+
474+
ifkeywordin ["gitdir","gitdir/i"]:
475+
value=osp.expanduser(value)
476+
flags= [re.IGNORECASE]ifkeyword=="gitdir/i"else []
477+
regexp=re.compile(fnmatch.translate(value),*flags)
478+
479+
ifany(
480+
regexp.match(path)isnotNone
481+
andself._repo.git_dir.startswith(path)
482+
forpathinglob.glob(value)
483+
):
484+
paths+=self.items(section)
485+
486+
487+
elifkeyword=="onbranch":
488+
ifvalue==self._repo.active_branch.name:
489+
paths+=self.items(section)
490+
491+
returnpaths
492+
458493
defread(self):
459494
"""Reads the data stored in the files we have been initialized with. It will
460495
ignore files that cannot be read, possibly leaving an empty configuration
@@ -492,7 +527,7 @@ def read(self):
492527
# Read includes and append those that we didn't handle yet
493528
# We expect all paths to be normalized and absolute (and will assure that is the case)
494529
ifself._has_includes():
495-
for_,include_pathinself.items('include'):
530+
for_,include_pathinself._included_paths():
496531
ifinclude_path.startswith('~'):
497532
include_path=osp.expanduser(include_path)
498533
ifnotosp.isabs(include_path):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp