Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 34683:3d6d4b12128e
tersestatus: make methods part of the dirnode class
Differential Revision: https://phab.mercurial-scm.org/D1042
author | Denis Laxalde <denis@laxalde.org> |
---|---|
date | Wed, 11 Oct 2017 21:19:19 +0200 |
parents | 7e3001b74ab3 |
children | 5d98674df18a |
comparison
equal
deleted
inserted
replaced
34682:7e3001b74ab3 | 34683:3d6d4b12128e |
---|---|
460 self._addfileindir(filename, status) | 460 self._addfileindir(filename, status) |
461 | 461 |
462 if status not in self.statuses: | 462 if status not in self.statuses: |
463 self.statuses.add(status) | 463 self.statuses.add(status) |
464 | 464 |
465 def _addfilestotersed(path, files, tersedict): | 465 def _addfilestotersed(self, tersedict): |
466 """ adds files to the their respective status list in the final tersed list | 466 """ |
467 | 467 adds files to the their respective status list in the final tersed list |
468 path is the path of parent directory of the file | 468 |
469 files is a list of tuple where each tuple is (filename, status) | 469 path is the path of parent directory of the file |
470 tersedict is a dictonary which contains each status abbreviation as key and | 470 files is a list of tuple where each tuple is (filename, status) |
471 list of files and tersed dirs in that status as value | 471 tersedict is a dictonary which contains each status abbreviation as key and |
472 """ | 472 list of files and tersed dirs in that status as value |
473 for f, st in files: | 473 """ |
474 tersedict[st].append(os.path.join(path, f)) | 474 for f, st in self.files: |
475 | 475 tersedict[st].append(os.path.join(self.path, f)) |
476 def _processtersestatus(subdir, tersedict, terseargs): | 476 |
477 """a recursive function which process status for a certain directory. | 477 def _processtersestatus(self, tersedict, terseargs): |
478 | 478 """ |
479 subdir is an oject of dirnode class defined below. each object of dirnode | 479 a recursive function which process status for a certain directory. |
480 class has a set of statuses which files in that directory has. This ease our | 480 |
481 check whether we can terse that directory or not. | 481 self is an oject of dirnode class defined below. each object of dirnode |
482 | 482 class has a set of statuses which files in that directory has. This ease |
483 tersedict is a dictonary which contains each status abbreviation as key and | 483 our check whether we can terse that directory or not. |
484 list of files and tersed dirs in that status as value. In each function call | 484 |
485 we are passing the same dict and adding files and dirs to it. | 485 tersedict is a dictonary which contains each status abbreviation as key |
486 | 486 and list of files and tersed dirs in that status as value. In each |
487 terseargs is the string of arguments passed by the user with `--terse` flag. | 487 function call we are passing the same dict and adding files and dirs |
488 | 488 to it. |
489 Following are the cases which can happen: | 489 |
490 | 490 terseargs is the string of arguments passed by the user with `--terse` |
491 1) All the files in the directory (including all the files in its | 491 flag. |
492 subdirectories) share the same status and the user has asked us to terse | 492 |
493 that status. -> we add the directory name to status list and return | 493 Following are the cases which can happen: |
494 | 494 |
495 2) If '1)' does not happen, we do following: | 495 1) All the files in the directory (including all the files in its |
496 | 496 subdirectories) share the same status and the user has asked us to terse |
497 a) Add all the files which are in this directory (only the ones in | 497 that status. -> we add the directory name to status list and return |
498 this directory, not the subdirs) to their respective status list | 498 |
499 | 499 2) If '1)' does not happen, we do following: |
500 b) Recurse the function on all the subdirectories of this directory | 500 |
501 """ | 501 a) Add all the files which are in this directory (only the ones in |
502 | 502 this directory, not the subdirs) to their respective status list |
503 if len(subdir.statuses) == 1: | 503 |
504 onlyst = subdir.statuses.pop() | 504 b) Recurse the function on all the subdirectories of this |
505 | 505 directory |
506 # Making sure we terse only when the status abbreviation is passed as | 506 """ |
507 # terse argument | 507 |
508 if onlyst in terseargs: | 508 if len(self.statuses) == 1: |
509 tersedict[onlyst].append(subdir.path + pycompat.ossep) | 509 onlyst = self.statuses.pop() |
510 return | 510 |
511 | 511 # Making sure we terse only when the status abbreviation is |
512 # add the files to status list | 512 # passed as terse argument |
513 _addfilestotersed(subdir.path, subdir.files, tersedict) | 513 if onlyst in terseargs: |
514 | 514 tersedict[onlyst].append(self.path + pycompat.ossep) |
515 #recurse on the subdirs | 515 return |
516 for dirobj in subdir.subdirs.values(): | 516 |
517 _processtersestatus(dirobj, tersedict, terseargs) | 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 def tersedir(statuslist, terseargs): | 524 def tersedir(statuslist, terseargs): |
520 """ | 525 """ |
521 terses the status if all the files in a directory shares the same status | 526 terses the status if all the files in a directory shares the same status |
522 | 527 |
551 for f in getattr(statuslist, attrname): | 556 for f in getattr(statuslist, attrname): |
552 rootobj.addfile(f, attrname[0]) | 557 rootobj.addfile(f, attrname[0]) |
553 tersedict[attrname[0]] = [] | 558 tersedict[attrname[0]] = [] |
554 | 559 |
555 # we won't be tersing the root dir, so add files in it | 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 # process each sub-directory and build tersedict | 563 # process each sub-directory and build tersedict |
559 for subdir in rootobj.subdirs.values(): | 564 for subdir in rootobj.subdirs.values(): |
560 _processtersestatus(subdir, tersedict, terseargs) | 565 subdir._processtersestatus(tersedict, terseargs) |
561 | 566 |
562 tersedlist = [] | 567 tersedlist = [] |
563 for st in allst: | 568 for st in allst: |
564 tersedict[st].sort() | 569 tersedict[st].sort() |
565 tersedlist.append(tersedict[st]) | 570 tersedlist.append(tersedict[st]) |