##// END OF EJS Templates
tersestatus: make methods part of the dirnode class...
Denis Laxalde -
r34684:3d6d4b12 default
parent child Browse files
Show More
@@ -462,29 +462,33 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
465 def _addfilestotersed(self, tersedict):
466 """
467 adds files to the their respective status list in the final tersed list
467 468
468 469 path is the path of parent directory of the file
469 470 files is a list of tuple where each tuple is (filename, status)
470 471 tersedict is a dictonary which contains each status abbreviation as key and
471 472 list of files and tersed dirs in that status as value
472 473 """
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.
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.
488 492
489 493 Following are the cases which can happen:
490 494
@@ -497,24 +501,25 def _processtersestatus(subdir, tersedic
497 501 a) Add all the files which are in this directory (only the ones in
498 502 this directory, not the subdirs) to their respective status list
499 503
500 b) Recurse the function on all the subdirectories of this directory
504 b) Recurse the function on all the subdirectories of this
505 directory
501 506 """
502 507
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 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
508 513 if onlyst in terseargs:
509 tersedict[onlyst].append(subdir.path + pycompat.ossep)
514 tersedict[onlyst].append(self.path + pycompat.ossep)
510 515 return
511 516
512 517 # add the files to status list
513 _addfilestotersed(subdir.path, subdir.files, tersedict)
518 self._addfilestotersed(tersedict)
514 519
515 520 #recurse on the subdirs
516 for dirobj in subdir.subdirs.values():
517 _processtersestatus(dirobj, tersedict, terseargs)
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 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