mercurial/cmdutil.py
changeset 38219 51e420a7a41a
parent 38164 aac4be30e250
child 38239 ead71b15efd5
equal deleted inserted replaced
38218:36ba5dba372d 38219:51e420a7a41a
   414 class dirnode(object):
   414 class dirnode(object):
   415     """
   415     """
   416     Represent a directory in user working copy with information required for
   416     Represent a directory in user working copy with information required for
   417     the purpose of tersing its status.
   417     the purpose of tersing its status.
   418 
   418 
   419     path is the path to the directory
   419     path is the path to the directory, without a trailing '/'
   420 
   420 
   421     statuses is a set of statuses of all files in this directory (this includes
   421     statuses is a set of statuses of all files in this directory (this includes
   422     all the files in all the subdirectories too)
   422     all the files in all the subdirectories too)
   423 
   423 
   424     files is a list of files which are direct child of this directory
   424     files is a list of files which are direct child of this directory
   451         if '/' in filename:
   451         if '/' in filename:
   452             subdir, filep = filename.split('/', 1)
   452             subdir, filep = filename.split('/', 1)
   453 
   453 
   454             # does the dirnode object for subdir exists
   454             # does the dirnode object for subdir exists
   455             if subdir not in self.subdirs:
   455             if subdir not in self.subdirs:
   456                 subdirpath = os.path.join(self.path, subdir)
   456                 subdirpath = pathutil.join(self.path, subdir)
   457                 self.subdirs[subdir] = dirnode(subdirpath)
   457                 self.subdirs[subdir] = dirnode(subdirpath)
   458 
   458 
   459             # try adding the file in subdir
   459             # try adding the file in subdir
   460             self.subdirs[subdir].addfile(filep, status)
   460             self.subdirs[subdir].addfile(filep, status)
   461 
   461 
   466             self.statuses.add(status)
   466             self.statuses.add(status)
   467 
   467 
   468     def iterfilepaths(self):
   468     def iterfilepaths(self):
   469         """Yield (status, path) for files directly under this directory."""
   469         """Yield (status, path) for files directly under this directory."""
   470         for f, st in self.files:
   470         for f, st in self.files:
   471             yield st, os.path.join(self.path, f)
   471             yield st, pathutil.join(self.path, f)
   472 
   472 
   473     def tersewalk(self, terseargs):
   473     def tersewalk(self, terseargs):
   474         """
   474         """
   475         Yield (status, path) obtained by processing the status of this
   475         Yield (status, path) obtained by processing the status of this
   476         dirnode.
   476         dirnode.
   480 
   480 
   481         Following are the cases which can happen:
   481         Following are the cases which can happen:
   482 
   482 
   483         1) All the files in the directory (including all the files in its
   483         1) All the files in the directory (including all the files in its
   484         subdirectories) share the same status and the user has asked us to terse
   484         subdirectories) share the same status and the user has asked us to terse
   485         that status. -> yield (status, dirpath)
   485         that status. -> yield (status, dirpath).  dirpath will end in '/'.
   486 
   486 
   487         2) Otherwise, we do following:
   487         2) Otherwise, we do following:
   488 
   488 
   489                 a) Yield (status, filepath)  for all the files which are in this
   489                 a) Yield (status, filepath)  for all the files which are in this
   490                     directory (only the ones in this directory, not the subdirs)
   490                     directory (only the ones in this directory, not the subdirs)
   497             onlyst = self.statuses.pop()
   497             onlyst = self.statuses.pop()
   498 
   498 
   499             # Making sure we terse only when the status abbreviation is
   499             # Making sure we terse only when the status abbreviation is
   500             # passed as terse argument
   500             # passed as terse argument
   501             if onlyst in terseargs:
   501             if onlyst in terseargs:
   502                 yield onlyst, self.path + pycompat.ossep
   502                 yield onlyst, self.path + '/'
   503                 return
   503                 return
   504 
   504 
   505         # add the files to status list
   505         # add the files to status list
   506         for st, fpath in self.iterfilepaths():
   506         for st, fpath in self.iterfilepaths():
   507             yield st, fpath
   507             yield st, fpath
   549         tersedict[st].append(fpath)
   549         tersedict[st].append(fpath)
   550 
   550 
   551     # process each sub-directory and build tersedict
   551     # process each sub-directory and build tersedict
   552     for subdir in rootobj.subdirs.values():
   552     for subdir in rootobj.subdirs.values():
   553         for st, f in subdir.tersewalk(terseargs):
   553         for st, f in subdir.tersewalk(terseargs):
   554             tersedict[st].append(util.pconvert(f))
   554             tersedict[st].append(f)
   555 
   555 
   556     tersedlist = []
   556     tersedlist = []
   557     for st in allst:
   557     for st in allst:
   558         tersedict[st].sort()
   558         tersedict[st].sort()
   559         tersedlist.append(tersedict[st])
   559         tersedlist.append(tersedict[st])