##// END OF EJS Templates
tersestatus: avoid modifying tersedict...
Denis Laxalde -
r34685:5d98674d default
parent child Browse files
Show More
@@ -462,19 +462,17 b' class dirnode(object):'
462 462 if status not in self.statuses:
463 463 self.statuses.add(status)
464 464
465 def _addfilestotersed(self, tersedict):
465 def iterfilepaths(self):
466 466 """
467 467 adds files to the their respective status list in the final tersed list
468 468
469 469 path is the path of parent directory of the file
470 470 files is a list of tuple where each tuple is (filename, status)
471 tersedict is a dictonary which contains each status abbreviation as key and
472 list of files and tersed dirs in that status as value
473 471 """
474 472 for f, st in self.files:
475 tersedict[st].append(os.path.join(self.path, f))
476
477 def _processtersestatus(self, tersedict, terseargs):
473 yield st, os.path.join(self.path, f)
474
475 def tersewalk(self, terseargs):
478 476 """
479 477 a recursive function which process status for a certain directory.
480 478
@@ -494,12 +492,12 b' class dirnode(object):'
494 492
495 493 1) All the files in the directory (including all the files in its
496 494 subdirectories) share the same status and the user has asked us to terse
497 that status. -> we add the directory name to status list and return
495 that status. -> yield (status, dirpath)
498 496
499 497 2) If '1)' does not happen, we do following:
500 498
501 a) Add all the files which are in this directory (only the ones in
502 this directory, not the subdirs) to their respective status list
499 a) Yield (status, filepath) for all the files which are in this
500 directory (only the ones in this directory, not the subdirs)
503 501
504 502 b) Recurse the function on all the subdirectories of this
505 503 directory
@@ -511,15 +509,17 b' class dirnode(object):'
511 509 # Making sure we terse only when the status abbreviation is
512 510 # passed as terse argument
513 511 if onlyst in terseargs:
514 tersedict[onlyst].append(self.path + pycompat.ossep)
512 yield onlyst, self.path + pycompat.ossep
515 513 return
516 514
517 515 # add the files to status list
518 self._addfilestotersed(tersedict)
516 for st, fpath in self.iterfilepaths():
517 yield st, fpath
519 518
520 519 #recurse on the subdirs
521 520 for dirobj in self.subdirs.values():
522 dirobj._processtersestatus(tersedict, terseargs)
521 for st, fpath in dirobj.tersewalk(terseargs):
522 yield st, fpath
523 523
524 524 def tersedir(statuslist, terseargs):
525 525 """
@@ -536,7 +536,7 b' def tersedir(statuslist, terseargs):'
536 536
537 537 tersedict (defined in the function) is a dictionary which has one word key
538 538 for each status and a list of files and dir in that status as the respective
539 value. The dictionary is passed to other helper functions which builds it.
539 value.
540 540 """
541 541 # the order matters here as that is used to produce final list
542 542 allst = ('m', 'a', 'r', 'd', 'u', 'i', 'c')
@@ -558,11 +558,13 b' def tersedir(statuslist, terseargs):'
558 558 tersedict[attrname[0]] = []
559 559
560 560 # we won't be tersing the root dir, so add files in it
561 rootobj._addfilestotersed(tersedict)
561 for st, fpath in rootobj.iterfilepaths():
562 tersedict[st].append(fpath)
562 563
563 564 # process each sub-directory and build tersedict
564 565 for subdir in rootobj.subdirs.values():
565 subdir._processtersestatus(tersedict, terseargs)
566 for st, f in subdir.tersewalk(terseargs):
567 tersedict[st].append(f)
566 568
567 569 tersedlist = []
568 570 for st in allst:
General Comments 0
You need to be logged in to leave comments. Login now