pike.git / lib / modules / Tools.pmod / Standalone.pmod / git_export_autodoc.pike

version» Context lines:

pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:201:    if (has_prefix(ref_name, "refs/remotes/origin/")) {    // Pretend that we have fast-forwarded all branches.    ref_name = "refs/heads/" + ref_name[sizeof("refs/remotes/origin/")..];    }    } else {    if (!has_prefix(ref_name, "refs/heads/") &&    !has_prefix(ref_name, "refs/tags/") &&    !has_prefix(ref_name, "refs/notes/source_revs")) continue;    }    if (ref_name == "refs/heads/HEAD") continue; +  if (has_prefix(ref_name, "refs/heads/") && +  (sizeof(ref_name/"/") != 3)) { +  // Avoid issues with rebased branches by only +  // extracting from the main branches. +  continue; +  }    refs[ref_name] = fields[0];    }   }      mapping(string:array(string)) get_commit(string git_dir, string sha1)   {    mapping(string:array(string)) res = ([]);    array(string) lines = Git.git(git_dir, "cat-file", "commit", sha1)/"\n";    foreach(lines; int no; string line) {    if (line == "") {
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:230:   string get_sha1_for_path(string git_dir, string tree_sha1, string path)   {    array(string) fields = Git.git(git_dir, "ls-tree", tree_sha1, path)/" ";    if (sizeof(fields) > 2) return (fields[2]/"\t")[0];    return "";   }      array(string) get_doc_parents(string doc_sha1)   {    array(string) parents = doc_to_parents[doc_sha1]; -  if (!zero_type(parents)) return parents; +  if (!undefinedp(parents)) return parents;    mapping(string:array(string)) commit = get_commit(git_dir, doc_sha1);    if (commit->parent) {    doc_to_parents[doc_sha1] = commit->parent;    }    // Get the sha1 for the autodoc.xml blob while we're at it.    if (commit->tree) {    string autodoc_sha1 =    get_sha1_for_path(git_dir, commit->tree[0], "autodoc.xml");    autodoc_hash[doc_sha1] = autodoc_sha1;    }    return parents;   }      string get_autodoc_hash(string doc_sha1)   {    string autodoc_sha1 = autodoc_hash[doc_sha1]; -  if (!zero_type(autodoc_sha1)) return autodoc_sha1; +  if (!undefinedp(autodoc_sha1)) return autodoc_sha1;    mapping(string:array(string)) commit = get_commit(git_dir, doc_sha1);    if (commit->tree) {    autodoc_sha1 =    get_sha1_for_path(git_dir, commit->tree[0], "autodoc.xml");    autodoc_hash[doc_sha1] = autodoc_sha1;    }    // Set the parents for the commit while we're at it.    if (commit->parent) {    doc_to_parents[doc_sha1] = commit->parent;    }
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:391:    }    if (Stdio.exist("1x1/01-baseline-preview.jpg")) {    return "extra-tests";    }    if (Stdio.exist("tools/sprshd")) {    return "nt-tools";    }    if (Stdio.is_dir("refs")) {    return "rxnpatch";    } +  if (Stdio.exist("src/sass.cpp")) { +  return "pike-modules/Sass";    } -  +  if (Stdio.exist("README.md")) { +  string readme = Stdio.read_bytes("README.md"); +  if (has_value(readme, "libsass")) { +  return "pike-modules/Sass"; +  } +  } +  }       error("Unable to determine version of Pike!\n");    return UNDEFINED;   }      string prev_img;      void extract_autodoc(mapping(string:array(string)) src_commit)   {    if (verbose) {
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:537:   void assemble_autodoc(mapping(string:array(string)) src_commit)   {    string refdocdir = "build/refdoc";    if (Stdio.exist("refdoc/structure/modref.xml")) {    // After modref.xml was added, we can use the refdoc files    // from the repository for assembly.    refdocdir = "refdoc";    }       exporter->export(combine_path(refdocdir, "src_images"), "images"); +  exporter->export(combine_path(refdocdir, "src_images"), "modref/images");    exporter->export(combine_path(refdocdir, "structure/modref.css"),    "modref/style.css"); -  +  exporter->export(combine_path(refdocdir, "structure/modref.js"), +  "modref/site.js");    if (verbose) {    progress("Assembling... ");    }    rm("build/onepage.xml");    rm("build/traditional.xml");    rm("build/modref.xml");    string pike_version = get_version();    string timestamp = (src_commit->author[0]/" ")[-2];    string ctimestamp = (src_commit->committer[0]/" ")[-2];   
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:586:    Tools.Standalone.assemble_autodoc()->    main(11, ({ "assemble_autodoc", "-o", "build/modref.xml",    "--keep-going", "-q", "--pike-version", pike_version,    "--timestamp", timestamp,    combine_path(refdocdir, "structure/modref.xml"),    "build/autodoc.xml" }));   }      void export_refdoc(mapping(string:array(string)) src_commit)   { -  string refdocdir = "build/refdoc"; //this_program::refdocdir; +  string refdocdir = "build/refdoc"; //this::refdocdir;    if (Stdio.exist("refdoc/structure/modref.html")) {    // After modref.xml was added, we can use the refdoc files    // from the repository for html.    refdocdir = "refdoc";    }       if (verbose) {    progress("HTML... ");    }    Tools.Standalone.autodoc_to_html converter =
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:627:    Tools.AutoDoc.FLAG_NO_DYNAMIC|Tools.AutoDoc.FLAG_COMPAT;    splitter->verbosity = Tools.AutoDoc.FLAG_QUIET;    splitter->image_path = "../images/";    splitter->default_namespace = "predef";    splitter->low_main("build/modref.xml",    combine_path(refdocdir, "structure/modref.html"),    "modref",    exporter);   }    + bool has_autodoc_filename( string diffline ) + { +  string path; +  if( sscanf( diffline, "%*s a/%[^ ]", path ) ) +  { +  if( has_suffix( path, ".bmml" ) ) return true; +  if( has_suffix( path, ".xml" ) && has_value( path, "refdoc" ) ) return true; +  if (has_prefix( path, "tutorial/" ) || has_value( path, "/doc/" )) { +  // BMML. +  return true; +  } +  if( (has_value( path, "/lenna" ) || has_value( path, "image_ill.pnm")) +  && Array.any(({"refdoc/src_images", +  "src/modules/Image/doc", +  "tutorial"}), +  Function.curry(has_value)(path))) +  return true; +  if ((has_prefix( path, "lib/" ) && +  (has_suffix( path, ".pike" ) || has_suffix( path, ".pmod")) || +  has_suffix( path, "/module.pmod.in" )) && +  (Stdio.file_size(work_dir + "/build/" + path + ".xml") > 64)) { +  // NB: The shortest possible autodoc xml file (without any content) +  // is ~60 bytes. Anything shorter doesn't contain any doc. +  +  // Edited Pike file with existing autodoc markup. +  return true; +  } +  } + } +  + bool has_doc_commits( string commit ) + { +  foreach( commit/"\n", string x ) +  { +  if(!strlen(x)) continue; +  if( x[0] == '+' || x[0] == '-' ) +  { +  if( (has_value( x, "*!" ) || has_value(x,"//!" )) && +  !has_value(x, "$""Id: ") ) +  return true; +  if (has_value(x, "inherit")) return true; +  } +  else if( has_prefix( x, "diff ") && has_autodoc_filename( x ) ) +  return true; +  } +  return false; + } +    void export_autodoc_for_ref(string ref)   {    string start_doc_rev;    string start_src_rev;    array(string) src_revs;    if ((start_doc_rev = doc_refs[ref]) &&    (start_src_rev = doc_to_src[start_doc_rev] &&    doc_to_src[start_doc_rev][-1])) {    src_revs = git("rev-list", "--topo-order",    start_src_rev + ".." + src_refs[ref])/"\n";
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:656:    if (verbose) {    progress("");    werror("\rExporting %s (%d/%d)... ", ref, i, sizeof(src_revs));    }    string doc_rev;    if (doc_rev = src_to_doc[src_rev]) {    exporter->reset(ref, doc_rev);    doc_refs[ref] = doc_rev;    continue;    } +  +  string doc_mark;    // Not previously converted. -  +  mapping(string:array(string)) src_commit = get_commit(work_git, src_rev);    -  // Check out the source. -  if (verbose) { -  progress("Checkout... "); -  } -  git("checkout", "-f", src_rev); -  git("clean", "-f", "-d", "-q", "src", "lib"); -  +     // Create a corresponding commit in the documentation. -  mapping(string:array(string)) src_commit = get_commit(work_git, src_rev); +     array(string) doc_parents = ({});    string prev_autodoc_sha1;    string prev_refdoc_sha1 = "";    if (src_commit->parent) { -  doc_parents = Array.uniq(map(src_commit->parent, src_to_doc)); +  doc_parents = Array.uniq(map(src_commit->parent, src_to_doc)) - +  ({ UNDEFINED });    prev_refdoc_sha1 = get_refdoc_sha1(src_commit->parent[0]);    }       if (sizeof(doc_parents) > 1) {    // Check if all of the parents are needed.    // We check the first 1000 unique parents.       ADT.Queue parent_queue = ADT.Queue(@doc_parents);    multiset(string) visited = (<>);    int loop_count;
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:705:    }    }    if (++loop_count >= 1000) break;    }    }       if (sizeof(doc_parents)) {    prev_autodoc_sha1 = get_autodoc_hash(doc_parents[0]);    }    -  string doc_mark; -  mixed err = catch { +  mixed err; +  do { +  if( doc_refs[ref] && src_commit->parent && +  !has_doc_commits(git("diff", "--pretty=raw", +  src_commit->parent[0] + ".." + src_rev)) ) +  { +  // Not relevant for autodoc. +  if (verbose) { +  progress("No documentation... "); +  } +  // Skip extraction, and just create the commit if needed, +  // and update the persistent state. +  continue; +  } +  +  // Check out the source. +  if (verbose) { +  progress("Checkout... "); +  } +  git("checkout", "-f", src_rev); +  git("clean", "-f", "-d", "-q", "src", "lib"); +  +  err = catch {    // Create the autodoc.xml blob.    extract_autodoc(src_commit);       if (!Stdio.exist(work_dir + "/build/autodoc.xml")) {    if (verbose) {    progress("Fail!");    }    break;    }    -  string autodoc_xml = Stdio.read_bytes(work_dir + "/build/autodoc.xml"); +  string autodoc_xml = +  Stdio.read_bytes(work_dir + "/build/autodoc.xml");    string new_autodoc_sha1 = Git.hash_blob(autodoc_xml);       // If it hasn't changed, we don't need to do anything.    if (new_autodoc_sha1 == prev_autodoc_sha1) {       // Except if the /refdoc directory has changed...    string refdoc_sha1 = get_refdoc_sha1(src_rev);    if (refdoc_sha1 == prev_refdoc_sha1)    break;    }       if (!sizeof(doc_parents)) {    // Force the commit to not have any parents.    exporter->reset(ref);    }    doc_mark = new_mark(); -  +  doc_refs[ref] = doc_mark;    exporter->commit(ref, doc_mark, src_commit->author[0],    src_commit->committer[0],    src_commit->message*"\n",    @doc_parents);       doc_to_parents[doc_mark] = doc_parents;       // Start from a clean tree.    exporter->filedeleteall();   
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:774:    if (Stdio.exist("build/traditional.xml")) {    exporter->export("build/traditional.xml", "traditional.xml");    }    if (Stdio.exist("build/modref.xml")) {    exporter->export("build/modref.xml", "modref.xml");    }       // Generate and export the html files.    export_refdoc(src_commit);    }; +  } while(0); +     if(!doc_mark) {    // No change since last commit.    if (sizeof(doc_parents) != 1) {    // We need to make a new commit, since we need to merge.    doc_mark = new_mark();    exporter->commit(ref, doc_mark, src_commit->author[0],    src_commit->committer[0],    src_commit->message*"\n",    @doc_parents);    autodoc_hash[doc_mark] = prev_autodoc_sha1;
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:1002:    werror("Move away %O, it is in the way.\n", work_dir);    exit(1);    }    git("clone", "-n", src_git, work_dir);    cd(work_dir);    } else {    cd(work_dir);    if (src_git) {    if (catch {    string old_src_git = -  String.trim_all_whites(git("config", "--get", +  String.trim(git("config", "--get",    "remotes.origin.url"));    if (old_src_git != src_git) {    if (verbose) {    werror("Updating source repository URL to %O.\n", src_git);    }    git("config", "--set", "remotes.origin.url", src_git);    }    }) {    if (verbose) {    werror("Adding remote repository URL %O as origin.\n", src_git);
pike.git/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike:1100:    }    }       foreach(src_refs; string ref; string sha1) {    rev_refs[sha1] += (< ref >);    }       // Start with the ref for HEAD.    string master_ref;    catch { -  master_ref = String.trim_all_whites(Git.git(work_git, "symbolic-ref", +  master_ref = String.trim(Git.git(work_git, "symbolic-ref",    "refs/remotes/origin/HEAD"));    if (has_prefix(master_ref, "refs/remotes/origin/")) {    master_ref = "refs/heads/" + master_ref[sizeof("refs/remotes/origin/")..];    }       Git.git(git_dir, "symbolic-ref", "HEAD", master_ref);    };       // Then export the remaining refs.    while (sizeof(src_refs)) {