implicitly check for unknown files (not part of a Mercurial repository);
authorwenzelm
Sun May 14 20:16:13 2017 +0200 (2017-05-14)
changeset 658322fb85623c386
parent 65831 3b197547c1d4
child 65833 95fd3b9888e6
implicitly check for unknown files (not part of a Mercurial repository);
src/Pure/General/mercurial.scala
src/Pure/Tools/build.scala
     1.1 --- a/src/Pure/General/mercurial.scala	Sun May 14 17:19:46 2017 +0200
     1.2 +++ b/src/Pure/General/mercurial.scala	Sun May 14 20:16:13 2017 +0200
     1.3 @@ -10,6 +10,9 @@
     1.4  
     1.5  import java.io.{File => JFile}
     1.6  
     1.7 +import scala.annotation.tailrec
     1.8 +import scala.collection.mutable
     1.9 +
    1.10  
    1.11  object Mercurial
    1.12  {
    1.13 @@ -155,4 +158,32 @@
    1.14        }
    1.15      }
    1.16    }
    1.17 +
    1.18 +
    1.19 +  /* unknown files */
    1.20 +
    1.21 +  def unknown_files(files: List[Path], ssh: Option[SSH.Session] = None): List[Path] =
    1.22 +  {
    1.23 +    val unknown = new mutable.ListBuffer[Path]
    1.24 +
    1.25 +    @tailrec def check(paths: List[Path])
    1.26 +    {
    1.27 +      paths match {
    1.28 +        case path :: rest =>
    1.29 +          find_repository(path, ssh) match {
    1.30 +            case None => unknown += path; check(rest)
    1.31 +            case Some(hg) =>
    1.32 +              val known =
    1.33 +                hg.known_files().iterator.map(name =>
    1.34 +                  (hg.root + Path.explode(name)).file.getCanonicalFile).toSet
    1.35 +              if (!known(path.file.getCanonicalFile)) unknown += path
    1.36 +              check(rest.filterNot(p => known(p.file.getCanonicalFile)))
    1.37 +          }
    1.38 +        case Nil =>
    1.39 +      }
    1.40 +    }
    1.41 +
    1.42 +    check(files)
    1.43 +    unknown.toList
    1.44 +  }
    1.45  }
     2.1 --- a/src/Pure/Tools/build.scala	Sun May 14 17:19:46 2017 +0200
     2.2 +++ b/src/Pure/Tools/build.scala	Sun May 14 20:16:13 2017 +0200
     2.3 @@ -338,6 +338,7 @@
     2.4    def build(
     2.5      options: Options,
     2.6      progress: Progress = No_Progress,
     2.7 +    check_unknown_files: Boolean = false,
     2.8      build_heap: Boolean = false,
     2.9      clean_build: Boolean = false,
    2.10      dirs: List[Path] = Nil,
    2.11 @@ -377,6 +378,19 @@
    2.12      def sources_stamp(name: String): List[String] =
    2.13        (selected_sessions(name).meta_digest :: deps.sources(name)).map(_.toString).sorted
    2.14  
    2.15 +    if (check_unknown_files) {
    2.16 +      val source_files =
    2.17 +        (for {
    2.18 +          (_, base) <- deps.session_bases.iterator
    2.19 +          (path, _) <- base.sources.iterator
    2.20 +        } yield path).toList
    2.21 +      val unknown_files = Mercurial.unknown_files(source_files)
    2.22 +      if (unknown_files.nonEmpty) {
    2.23 +        progress.echo_warning("Unknown files (not part of a Mercurial repository):" +
    2.24 +          unknown_files.map(path => path.expand.implode).sorted.mkString("\n  ", "\n  ", ""))
    2.25 +      }
    2.26 +    }
    2.27 +
    2.28  
    2.29      /* main build process */
    2.30  
    2.31 @@ -680,6 +694,7 @@
    2.32      val results =
    2.33        progress.interrupt_handler {
    2.34          build(options, progress,
    2.35 +          check_unknown_files = Mercurial.is_repository(Path.explode("~~")),
    2.36            build_heap = build_heap,
    2.37            clean_build = clean_build,
    2.38            dirs = dirs,