size: 1 KiB
| 1 | const std = @import("std"); |
| 2 | const mem = std.mem; |
| 3 | const posix = std.posix; |
| 4 | |
| 5 | // Here are all environment variables used for config: |
| 6 | |
| 7 | /// Default 0. |
| 8 | /// If 0, blob object pages that already exist will be skipped. |
| 9 | /// If 1, they will be regenerated. |
| 10 | /// Useful when there's been updates on blob page generation logic. |
| 11 | const KHOE_FULL_REGEN = "KHOE_FULL_REGEN"; |
| 12 | |
| 13 | /// TODO: not implemented yet |
| 14 | /// Default empty. |
| 15 | /// If non-empty, only specified repo's objects will be generated. |
| 16 | /// Convenient when used as a post-update git hook, so that the repo being |
| 17 | /// pushed stays updated. |
| 18 | const KHOE_REPO = "KHOE_REPO"; |
| 19 | |
| 20 | /// Default 0. |
| 21 | /// If 0, only generate blobs for latest tree in HEAD. |
| 22 | /// If 1, all blobs from all commits of HEAD branch will be generated. |
| 23 | /// It's recommended to first run khoe with this on to generate the full set, |
| 24 | /// then leave it off in subsequent runs to save time. As long as we don't |
| 25 | /// delete anything, links to blob object pages will stay valid. |
| 26 | const KHOE_HISTORICAL_BLOBS = "KHOE_HISTORICAL_BLOBS"; |
| 27 | |
| 28 | pub const Conf = struct { |
| 29 | full_regen: bool, |
| 30 | repo: ?[:0]const u8, |
| 31 | historical_blobs: bool, |
| 32 | }; |
| 33 | |
| 34 | pub fn fromEnv() Conf { |
| 35 | const full_regen = posix.getenv(KHOE_FULL_REGEN) orelse "0"; |
| 36 | const repo = posix.getenv(KHOE_REPO); |
| 37 | const historical_blobs = posix.getenv(KHOE_HISTORICAL_BLOBS) orelse "0"; |
| 38 | |
| 39 | return Conf{ |
| 40 | .full_regen = mem.eql(u8, full_regen, "1"), |
| 41 | .repo = repo, |
| 42 | .historical_blobs = mem.eql(u8, historical_blobs, "1"), |
| 43 | }; |
| 44 | } |