Git hosting and a container registry in one Rust binary (axum + Astro)
| 1 | #!/usr/bin/env python3 |
| 2 | """Build backend/src/languages/linguist.json from GitHub Linguist's data files. |
| 3 | |
| 4 | irongit detects languages the way GitHub does, with Linguist's own tables: |
| 5 | languages.yml (names, colors, groups, extensions, filenames, interpreters, |
| 6 | aliases), vendor.yml and documentation.yml (excluded paths), generic.yml |
| 7 | (extensions too vague to decide on), and heuristics.yml (content rules for |
| 8 | shared extensions such as .h, .m, .sql or .pl). This script downloads them for |
| 9 | one Linguist release and writes a compact JSON the server embeds. |
| 10 | |
| 11 | python3 scripts/gen-linguist.py # the release pinned below |
| 12 | python3 scripts/gen-linguist.py v9.8.0 # another release |
| 13 | |
| 14 | Heuristic patterns are Ruby regexes; they are rewritten for Rust's regex crate |
| 15 | here (Ruby's ^ and $ always match at line breaks, Ruby's m flag is Rust's s, |
| 16 | a stray { is a literal). A few use lookarounds or subroutines Rust lacks; a |
| 17 | server test checks that those only choose between data and prose formats, |
| 18 | which never count, so a pattern that never matches costs nothing. |
| 19 | |
| 20 | Linguist is MIT licensed: https://github.com/github-linguist/linguist |
| 21 | """ |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | = |
| 32 | = f |
| 33 | = .. / |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | return |
| 39 | |
| 40 | |
| 41 | |
| 42 | """One Ruby regex as a Rust one with the same meaning.""" |
| 43 | # Ruby's inline m flag is dot-matches-newline, which Rust calls s. |
| 44 | |
| 45 | , = , |
| 46 | return + + |
| 47 | = |
| 48 | # {,n} is Ruby shorthand for {0,n}. |
| 49 | = |
| 50 | # Ruby reads a { that starts no repetition as a literal; Rust wants \{. |
| 51 | = |
| 52 | # Rust has no lookbehind; "not after {" is spelled out. |
| 53 | = |
| 54 | # Ruby's ^ and $ are always line anchors. |
| 55 | return + |
| 56 | |
| 57 | |
| 58 | |
| 59 | = |
| 60 | |
| 61 | return |
| 62 | return |
| 63 | |
| 64 | |
| 65 | |
| 66 | = |
| 67 | = |
| 68 | = |
| 69 | = |
| 70 | = |
| 71 | |
| 72 | = |
| 73 | = |
| 74 | |
| 75 | = |
| 76 | |
| 77 | = |
| 78 | |
| 79 | = |
| 80 | |
| 81 | |
| 82 | = |
| 83 | |
| 84 | |
| 85 | = |
| 86 | |
| 87 | |
| 88 | |
| 89 | return |
| 90 | |
| 91 | return |
| 92 | |
| 93 | return |
| 94 | |
| 95 | return |
| 96 | return |
| 97 | |
| 98 | = |
| 99 | |
| 100 | = |
| 101 | |
| 102 | = |
| 103 | |
| 104 | |
| 105 | |
| 106 | = |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 |