|
13 | 13 | importlogging
|
14 | 14 | importos
|
15 | 15 | importre
|
| 16 | +importglob |
| 17 | +importfnmatch |
16 | 18 | fromcollectionsimportOrderedDict
|
17 | 19 |
|
18 | 20 | fromgit.compatimport (
|
@@ -455,6 +457,39 @@ def _has_includes(self):
|
455 | 457 | forsectioninself.sections()
|
456 | 458 | )
|
457 | 459 |
|
| 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 | + |
458 | 493 | defread(self):
|
459 | 494 | """Reads the data stored in the files we have been initialized with. It will
|
460 | 495 | ignore files that cannot be read, possibly leaving an empty configuration
|
@@ -492,7 +527,7 @@ def read(self):
|
492 | 527 | # Read includes and append those that we didn't handle yet
|
493 | 528 | # We expect all paths to be normalized and absolute (and will assure that is the case)
|
494 | 529 | ifself._has_includes():
|
495 |
| -for_,include_pathinself.items('include'): |
| 530 | +for_,include_pathinself._included_paths(): |
496 | 531 | ifinclude_path.startswith('~'):
|
497 | 532 | include_path=osp.expanduser(include_path)
|
498 | 533 | ifnotosp.isabs(include_path):
|
|