D6403: util: make util.dirs() and util.finddirs() include root directory (API)

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri May 17 13:58:26 EDT 2019


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This changes the behavior of test-origbackup-conflict.t so it no
  longer errors out when the backup path points to an existing
  file. Instead, it replaces the file by a directory. That seems
  reasonable to me.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6403

AFFECTED FILES
  mercurial/cext/dirs.c
  mercurial/cext/parsers.c
  mercurial/hgweb/hgwebdir_mod.py
  mercurial/match.py
  mercurial/policy.py
  mercurial/util.py
  tests/test-origbackup-conflict.t

CHANGE DETAILS

diff --git a/tests/test-origbackup-conflict.t b/tests/test-origbackup-conflict.t
--- a/tests/test-origbackup-conflict.t
+++ b/tests/test-origbackup-conflict.t
@@ -129,8 +129,9 @@
   b/c: replacing untracked file
   getting b/c
   creating directory: $TESTTMP/repo/.hg/badorigbackups/b
-  abort: $ENOTDIR$: *$TESTTMP/repo/.hg/badorigbackups/b* (glob)
-  [255]
-  $ cat .hg/badorigbackups
-  data
-
+  removing conflicting file: $TESTTMP/repo/.hg/badorigbackups
+  getting d
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (activating bookmark c1)
+  $ ls .hg/badorigbackups/b
+  c
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -3209,6 +3209,7 @@
     while pos != -1:
         yield path[:pos]
         pos = path.rfind('/', 0, pos)
+    yield ''
 
 
 # convenient shortcut
diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -69,7 +69,7 @@
     (r'cext', r'bdiff'): 3,
     (r'cext', r'mpatch'): 1,
     (r'cext', r'osutil'): 4,
-    (r'cext', r'parsers'): 12,
+    (r'cext', r'parsers'): 13,
 }
 
 # map import request to other package or module
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -539,8 +539,7 @@
         dir = normalizerootdir(dir, 'visitdir')
         if self._prefix and dir in self._fileset:
             return 'all'
-        return ('' in self._fileset or
-                dir in self._fileset or
+        return (dir in self._fileset or
                 dir in self._dirs or
                 any(parentdir in self._fileset
                     for parentdir in util.finddirs(dir)))
@@ -621,8 +620,7 @@
         dir = normalizerootdir(dir, 'visitdir')
         if self._prefix and dir in self._roots:
             return 'all'
-        return ('' in self._roots or
-                dir in self._roots or
+        return (dir in self._roots or
                 dir in self._dirs or
                 dir in self._parents or
                 any(parentdir in self._roots
@@ -1386,14 +1384,14 @@
     >>> _rootsdirsandparents(
     ...     [(b'glob', b'g/h/*', b''), (b'glob', b'g/h', b''),
     ...      (b'glob', b'g*', b'')])
-    (['g/h', 'g/h', ''], [], ['g', ''])
+    (['g/h', 'g/h', ''], [], ['', 'g'])
     >>> _rootsdirsandparents(
     ...     [(b'rootfilesin', b'g/h', b''), (b'rootfilesin', b'', b'')])
-    ([], ['g/h', ''], ['g', ''])
+    ([], ['g/h', ''], ['', 'g'])
     >>> _rootsdirsandparents(
     ...     [(b'relpath', b'r', b''), (b'path', b'p/p', b''),
     ...      (b'path', b'', b'')])
-    (['r', 'p/p', ''], [], ['p', ''])
+    (['r', 'p/p', ''], [], ['', 'p'])
     >>> _rootsdirsandparents(
     ...     [(b'relglob', b'rg*', b''), (b're', b're/', b''),
     ...      (b'relre', b'rr', b'')])
@@ -1406,8 +1404,6 @@
     # scanned to get to either the roots or the other exact directories.
     p.extend(util.dirs(d))
     p.extend(util.dirs(r))
-    # util.dirs() does not include the root directory, so add it manually
-    p.append('')
 
     # FIXME: all uses of this function convert these to sets, do so before
     # returning.
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -414,14 +414,10 @@
                     return self.makeindex(req, res, tmpl, subdir)
 
             def _virtualdirs():
-                # Check the full virtual path, each parent, and the root ('')
-                if virtual != '':
-                    yield virtual
-
-                    for p in util.finddirs(virtual):
-                        yield p
-
-                yield ''
+                # Check the full virtual path, and each parent
+                yield virtual
+                for p in util.finddirs(virtual):
+                    yield p
 
             for virtualrepo in _virtualdirs():
                 real = repos.get(virtualrepo)
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -667,7 +667,7 @@
 void manifest_module_init(PyObject *mod);
 void revlog_module_init(PyObject *mod);
 
-static const int version = 12;
+static const int version = 13;
 
 static void module_init(PyObject *mod)
 {
diff --git a/mercurial/cext/dirs.c b/mercurial/cext/dirs.c
--- a/mercurial/cext/dirs.c
+++ b/mercurial/cext/dirs.c
@@ -42,6 +42,9 @@
 			break;
 		pos -= 1;
 	}
+	if (pos == -1) {
+	  return 0;
+	}
 
 	return pos;
 }



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list