Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHG3d6d4b12128e: tersestatus: make methods part of the dirnode class
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| durin42 |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/cmdutil.py (115 lines) |
| self.subdirs[subdir].addfile(filep, status) | self.subdirs[subdir].addfile(filep, status) | ||||
| else: | else: | ||||
| self._addfileindir(filename, status) | self._addfileindir(filename, status) | ||||
| if status not in self.statuses: | if status not in self.statuses: | ||||
| self.statuses.add(status) | self.statuses.add(status) | ||||
| def _addfilestotersed(path, files, tersedict): | def _addfilestotersed(self, tersedict): | ||||
| """ adds files to the their respective status list in the final tersed list | """ | ||||
| adds files to the their respective status list in the final tersed list | |||||
| path is the path of parent directory of the file | path is the path of parent directory of the file | ||||
| files is a list of tuple where each tuple is (filename, status) | files is a list of tuple where each tuple is (filename, status) | ||||
| tersedict is a dictonary which contains each status abbreviation as key and | tersedict is a dictonary which contains each status abbreviation as key and | ||||
| list of files and tersed dirs in that status as value | list of files and tersed dirs in that status as value | ||||
| """ | """ | ||||
| for f, st in files: | for f, st in self.files: | ||||
| tersedict[st].append(os.path.join(path, f)) | tersedict[st].append(os.path.join(self.path, f)) | ||||
| def _processtersestatus(subdir, tersedict, terseargs): | def _processtersestatus(self, tersedict, terseargs): | ||||
| """a recursive function which process status for a certain directory. | """ | ||||
| a recursive function which process status for a certain directory. | |||||
| subdir is an oject of dirnode class defined below. each object of dirnode | self is an oject of dirnode class defined below. each object of dirnode | ||||
| class has a set of statuses which files in that directory has. This ease our | class has a set of statuses which files in that directory has. This ease | ||||
| check whether we can terse that directory or not. | our check whether we can terse that directory or not. | ||||
| tersedict is a dictonary which contains each status abbreviation as key and | tersedict is a dictonary which contains each status abbreviation as key | ||||
| list of files and tersed dirs in that status as value. In each function call | and list of files and tersed dirs in that status as value. In each | ||||
| we are passing the same dict and adding files and dirs to it. | function call we are passing the same dict and adding files and dirs | ||||
| to it. | |||||
| terseargs is the string of arguments passed by the user with `--terse` flag. | terseargs is the string of arguments passed by the user with `--terse` | ||||
| flag. | |||||
| Following are the cases which can happen: | Following are the cases which can happen: | ||||
| 1) All the files in the directory (including all the files in its | 1) All the files in the directory (including all the files in its | ||||
| subdirectories) share the same status and the user has asked us to terse | subdirectories) share the same status and the user has asked us to terse | ||||
| that status. -> we add the directory name to status list and return | that status. -> we add the directory name to status list and return | ||||
| 2) If '1)' does not happen, we do following: | 2) If '1)' does not happen, we do following: | ||||
| a) Add all the files which are in this directory (only the ones in | a) Add all the files which are in this directory (only the ones in | ||||
| this directory, not the subdirs) to their respective status list | this directory, not the subdirs) to their respective status list | ||||
| b) Recurse the function on all the subdirectories of this directory | b) Recurse the function on all the subdirectories of this | ||||
| directory | |||||
| """ | """ | ||||
| if len(subdir.statuses) == 1: | if len(self.statuses) == 1: | ||||
| onlyst = subdir.statuses.pop() | onlyst = self.statuses.pop() | ||||
| # Making sure we terse only when the status abbreviation is passed as | # Making sure we terse only when the status abbreviation is | ||||
| # terse argument | # passed as terse argument | ||||
| if onlyst in terseargs: | if onlyst in terseargs: | ||||
| tersedict[onlyst].append(subdir.path + pycompat.ossep) | tersedict[onlyst].append(self.path + pycompat.ossep) | ||||
| return | return | ||||
| # add the files to status list | # add the files to status list | ||||
| _addfilestotersed(subdir.path, subdir.files, tersedict) | self._addfilestotersed(tersedict) | ||||
| #recurse on the subdirs | #recurse on the subdirs | ||||
| for dirobj in subdir.subdirs.values(): | for dirobj in self.subdirs.values(): | ||||
| _processtersestatus(dirobj, tersedict, terseargs) | dirobj._processtersestatus(tersedict, terseargs) | ||||
| def tersedir(statuslist, terseargs): | def tersedir(statuslist, terseargs): | ||||
| """ | """ | ||||
| terses the status if all the files in a directory shares the same status | terses the status if all the files in a directory shares the same status | ||||
| statuslist is scmutil.status() object which contains a list of files for | statuslist is scmutil.status() object which contains a list of files for | ||||
| each status. | each status. | ||||
| terseargs is string which is passed by the user as the argument to `--terse` | terseargs is string which is passed by the user as the argument to `--terse` | ||||
| tersedict = {} | tersedict = {} | ||||
| for attrname in pstatus: | for attrname in pstatus: | ||||
| for f in getattr(statuslist, attrname): | for f in getattr(statuslist, attrname): | ||||
| rootobj.addfile(f, attrname[0]) | rootobj.addfile(f, attrname[0]) | ||||
| tersedict[attrname[0]] = [] | tersedict[attrname[0]] = [] | ||||
| # we won't be tersing the root dir, so add files in it | # we won't be tersing the root dir, so add files in it | ||||
| _addfilestotersed(rootobj.path, rootobj.files, tersedict) | rootobj._addfilestotersed(tersedict) | ||||
| # process each sub-directory and build tersedict | # process each sub-directory and build tersedict | ||||
| for subdir in rootobj.subdirs.values(): | for subdir in rootobj.subdirs.values(): | ||||
| _processtersestatus(subdir, tersedict, terseargs) | subdir._processtersestatus(tersedict, terseargs) | ||||
| tersedlist = [] | tersedlist = [] | ||||
| for st in allst: | for st in allst: | ||||
| tersedict[st].sort() | tersedict[st].sort() | ||||
| tersedlist.append(tersedict[st]) | tersedlist.append(tersedict[st]) | ||||
| return tersedlist | return tersedlist | ||||