diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -404,11 +404,6 @@ return commit(ui, repo, recordinwlock, pats, opts) - -# extracted at module level as it's required each time a file will be added -# to dirnode class object below -pathsep = pycompat.ossep - class dirnode(object): """ Represent a directory in user working copy with information required for @@ -435,6 +430,19 @@ """Add a file in this directory as a direct child.""" self.files.append((filename, status)) + def _splitbyroot(self, path): + """ + splits the path from the first occurence of os.sep and returns a tuple + (rootdirectory, restofthepath) + """ + #XXX: must be replaced with pathlib once we drop Py2.7 + parentdir = os.path.dirname(path) + temp = path + while parentdir: + temp = parentdir + parentdir = os.path.dirname(parentdir) + return temp, path[len(temp) + 1:] + def addfile(self, filename, status): """ Add a file to this directory or to its direct parent directory. @@ -446,8 +454,8 @@ # the filename contains a path separator, it means it's not the direct # child of this directory - if pathsep in filename: - subdir, filep = filename.split(pathsep, 1) + if pycompat.ossep in filename: + subdir, filep = self._splitbyroot(filename) # does the dirnode object for subdir exists if subdir not in self.subdirs: