##// END OF EJS Templates
tersestatus: make methods part of the dirnode class...
Denis Laxalde -
r34684:3d6d4b12 default
parent child Browse files
Show More
@@ -462,59 +462,64 b' class dirnode(object):'
462 462 if status not in self.statuses:
463 463 self.statuses.add(status)
464 464
465 def _addfilestotersed(path, files, tersedict):
466 """ adds files to the their respective status list in the final tersed list
467
468 path is the path of parent directory of the file
469 files is a list of tuple where each tuple is (filename, status)
470 tersedict is a dictonary which contains each status abbreviation as key and
471 list of files and tersed dirs in that status as value
472 """
473 for f, st in files:
474 tersedict[st].append(os.path.join(path, f))
475
476 def _processtersestatus(subdir, tersedict, terseargs):
477 """a recursive function which process status for a certain directory.
478
479 subdir is an oject of dirnode class defined below. each object of dirnode
480 class has a set of statuses which files in that directory has. This ease our
481 check whether we can terse that directory or not.
482
483 tersedict is a dictonary which contains each status abbreviation as key and
484 list of files and tersed dirs in that status as value. In each function call
485 we are passing the same dict and adding files and dirs to it.
486
487 terseargs is the string of arguments passed by the user with `--terse` flag.
488
489 Following are the cases which can happen:
490
491 1) All the files in the directory (including all the files in its
492 subdirectories) share the same status and the user has asked us to terse
493 that status. -> we add the directory name to status list and return
494
495 2) If '1)' does not happen, we do following:
496
497 a) Add all the files which are in this directory (only the ones in
498 this directory, not the subdirs) to their respective status list
499
500 b) Recurse the function on all the subdirectories of this directory
501 """
502
503 if len(subdir.statuses) == 1:
504 onlyst = subdir.statuses.pop()
505
506 # Making sure we terse only when the status abbreviation is passed as
507 # terse argument
508 if onlyst in terseargs:
509 tersedict[onlyst].append(subdir.path + pycompat.ossep)
510 return
511
512 # add the files to status list
513 _addfilestotersed(subdir.path, subdir.files, tersedict)
514
515 #recurse on the subdirs
516 for dirobj in subdir.subdirs.values():
517 _processtersestatus(dirobj, tersedict, terseargs)
465 def _addfilestotersed(self, tersedict):
466 """
467 adds files to the their respective status list in the final tersed list
468
469 path is the path of parent directory of the file
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 """
474 for f, st in self.files:
475 tersedict[st].append(os.path.join(self.path, f))
476
477 def _processtersestatus(self, tersedict, terseargs):
478 """
479 a recursive function which process status for a certain directory.
480
481 self is an oject of dirnode class defined below. each object of dirnode
482 class has a set of statuses which files in that directory has. This ease
483 our check whether we can terse that directory or not.
484
485 tersedict is a dictonary which contains each status abbreviation as key
486 and list of files and tersed dirs in that status as value. In each
487 function call we are passing the same dict and adding files and dirs
488 to it.
489
490 terseargs is the string of arguments passed by the user with `--terse`
491 flag.
492
493 Following are the cases which can happen:
494
495 1) All the files in the directory (including all the files in its
496 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
498
499 2) If '1)' does not happen, we do following:
500
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
503
504 b) Recurse the function on all the subdirectories of this
505 directory
506 """
507
508 if len(self.statuses) == 1:
509 onlyst = self.statuses.pop()
510
511 # Making sure we terse only when the status abbreviation is
512 # passed as terse argument
513 if onlyst in terseargs:
514 tersedict[onlyst].append(self.path + pycompat.ossep)
515 return
516
517 # add the files to status list
518 self._addfilestotersed(tersedict)
519
520 #recurse on the subdirs
521 for dirobj in self.subdirs.values():
522 dirobj._processtersestatus(tersedict, terseargs)
518 523
519 524 def tersedir(statuslist, terseargs):
520 525 """
@@ -553,11 +558,11 b' def tersedir(statuslist, terseargs):'
553 558 tersedict[attrname[0]] = []
554 559
555 560 # we won't be tersing the root dir, so add files in it
556 _addfilestotersed(rootobj.path, rootobj.files, tersedict)
561 rootobj._addfilestotersed(tersedict)
557 562
558 563 # process each sub-directory and build tersedict
559 564 for subdir in rootobj.subdirs.values():
560 _processtersestatus(subdir, tersedict, terseargs)
565 subdir._processtersestatus(tersedict, terseargs)
561 566
562 567 tersedlist = []
563 568 for st in allst:
General Comments 0
You need to be logged in to leave comments. Login now