API
The command line tool is a thin wrapper around these functions; they can also be used from Julia (using UpstreamSync).
Entry points
UpstreamSync — Module
UpstreamSyncKeep forks that follow the main/dev convention in sync with upstream release tarballs:
mainholds the pristine upstream tree, imported from release tarballs and taggedupstream/X.Y.Z;devholds the fork (build system, fixes, CI, site).
The entry point for scripts is main; the building blocks are check, import_release, tag_release, merge_plan and export_changes. Nothing is ever pushed.
UpstreamSync.main — Function
main(args; io=stdout) -> IntCommand line entry point (see bin/upstream-sync.jl and ExitCode). Returns the exit status instead of exiting.
UpstreamSync.ExitCode — Module
Exit status of the upstream-sync command line tool.
ExitCode.OK(0): success; forcheck, every upstream is up to date.ExitCode.ERROR(1): an error occurred.ExitCode.NEW_RELEASE(10):checkfound an upstream release newer than the latestupstream/X.Y.Ztag.
UpstreamSync.check — Function
check(u; repo=nothing, io=stdout, index_html=nothing) -> CheckResultList the upstream releases (from u.index_url, or the given index_html), the latest one and the latest imported one; report whether a newer release exists.
UpstreamSync.import_release — Function
import_release(u, version; repo, cache=cache_dir(), io=stdout,
force=false, offline=false, allow_stale=false) -> ImportResultImport an upstream release tarball into the local clone repo: download (cached) and verify it, then create the commit "import upstream <name> X.Y.Z" whose tree is the tarball's content (top directory stripped) plus the kept paths of the upstream branch, on the new branch upstream-import/X.Y.Z (parent: the upstream branch). The body records the source URL, the checksum and the tree hash (Tree: <hash>). Author and committer are the local git identity. No tag is created: once the pull request is merged (with any method), tag_release tags the commit of the upstream branch that has this tree. The working tree is not touched and nothing is pushed. With force, an existing branch and tag are replaced. The import refuses to start when the local upstream branch differs from origin's, unless allow_stale (see check_not_stale).
UpstreamSync.tag_release — Function
tag_release(u, version; repo, io=stdout, force=false, offline=false)
-> TagResultRun after the import pull request is merged, with any merge method. Fetch the upstream branch from origin (unless offline; without an origin remote the local branch is used), then find on it the commit with the tree of the import:
- the import commit itself if it is on the branch (merge commit or fast-forward);
- otherwise the oldest commit with the same tree (squash or rebase merge).
The import tree is read from the import branch (upstream-import/X.Y.Z, local or origin/), or, once that branch is deleted, from the "import upstream <name> X.Y.Z" commit on the upstream branch: the Tree: line of its message, or else (imports made before that line existed) its own tree. Create the annotated tag upstream/X.Y.Z there, with the source URL and checksum of the import. Refuse when no commit matches, or when the tag already exists on another commit (unless force). Never pushes.
UpstreamSync.merge_plan — Function
merge_plan(u, version; repo, cache=cache_dir(), output=nothing,
io=stdout, force=false, allow_stale=false,
resolve_expected=false, worktree=nothing) -> MergePlanCreate the branch sync/X.Y.Z from the fork branch, try git merge --no-commit upstream-import/X.Y.Z on it (in a temporary worktree, so the working tree of repo is not touched), abort the merge, and write a Markdown report to output (default merge-plan-<name>-X.Y.Z.md in the current directory).
"Deleted by us" conflicts on fork_excluded_paths are reported as expected, apart from the real conflicts, and so are the files upstream added under fork_excluded_paths (merged without a conflict). Files added elsewhere are listed, for the fork's build. With resolve_expected, the merge is not aborted: it is left in progress in worktree (default default_sync_worktree) with the expected conflicts resolved by git rm and the real ones still marked. Nothing is committed or pushed. Refuses a local fork branch that differs from origin's unless allow_stale.
UpstreamSync.export_changes — Function
export_changes(u; repo, io=nothing, output=nothing) -> ExportReportList our changes to the upstream sources: the commits on the fork branch that are not on the upstream branch and touch export_paths (minus export_exclude; with export_modified_only, only modifications of existing files count), oldest first, with their GitHub URLs, plus the diffstat of upstream...fork on the same paths. The Markdown is written to output and/or printed to io when given.
Results
UpstreamSync.CheckResult — Type
CheckResultOutcome of check: the upstream releases, the latest release version, the versions already imported (from upstream/X.Y.Z tags), the latest of them (imported, or nothing), and new_release.
UpstreamSync.ImportResult — Type
ImportResultOutcome of import_release: the new commit and its branch, the tag that tag_release will create once the pull request is merged, the source url and checksum, the parent commit (the upstream branch), and the tarball paths dropped because they fall in a kept path.
UpstreamSync.TagResult — Type
TagResultOutcome of tag_release: the annotated tag on commit (of the upstream branch, ref), whose tree is the import tree; how tells how the commit was found.
UpstreamSync.MergePlan — Type
MergePlanOutcome of merge_plan. changes are the upstream file changes, overlap the upstream-changed files that the fork also modified, conflicts the real conflicts left by git merge, expected the "deleted by us" conflicts on fork_excluded_paths (resolved by keeping the deletion), excluded_additions the files upstream added under fork_excluded_paths (git merges them without a conflict; they are removed like the expected conflicts), new_files the other files upstream added (the fork's build may need to list them), worktree the directory holding the merge in progress (with resolve_expected, else nothing), markdown the report.
UpstreamSync.FileChange — Type
FileChange(path, status, added, deleted, area)One file changed upstream between two imports (status: A, M, D, T; added/deleted lines, -1 for binary files).
UpstreamSync.Conflict — Type
Conflict(path, status, area)A file left conflicted by git merge (status such as "both modified", "deleted by us").
UpstreamSync.ExportReport — Type
ExportReportOutcome of export_changes: our commits touching the upstream sources, the diffstat of upstream...fork on those paths, and the markdown report.
UpstreamSync.CommitInfo — Type
CommitInfo(hash, date, subject, url, files)Configuration
UpstreamSync.Upstream — Type
UpstreamOne fork and its upstream, as configured in upstreams.toml (see the comments in that file for the meaning of every field).
UpstreamSync.load_config — Function
load_config(path = default_config_path()) -> Dict{String,Upstream}UpstreamSync.default_config_path — Function
default_config_path() -> StringThe upstreams.toml shipped at the root of this project.
UpstreamSync.get_upstream — Function
get_upstream(config, name) -> UpstreamUpstreamSync.fork_excluded — Function
fork_excluded(u, path) -> BoolWhether path is one of the upstream files that the fork branch intentionally does not carry (fork_excluded_paths, patterns as in pathmatch).
UpstreamSync.cache_dir — Function
cache_dir() -> StringDownload cache: $UPSTREAM_SYNC_CACHE, or cache/ at the project root (ignored by git). Tarballs are stored as <cache>/<name>/<file>.
Building blocks
UpstreamSync.Release — Type
Release(version, filename)An upstream release found in the download directory index.
UpstreamSync.parse_index — Function
parse_index(html, regex) -> Vector{Release}Releases listed in an (Apache-style) directory index: every link whose file name matches regex, whose first capture group is the X.Y.Z version. Sorted by version, one entry per version.
UpstreamSync.latest_release — Function
latest_release(releases) -> Union{Release, Nothing}UpstreamSync.parse_version — Function
parse_version(s) -> VersionNumberParse a strict X.Y.Z release version (no v prefix, no suffix).
UpstreamSync.is_newer — Function
is_newer(latest, imported) -> BoolWhether the latest upstream release is newer than the imported one. nothing means "no release" (latest) or "nothing imported yet" (imported).
UpstreamSync.parse_upstream_tags — Function
parse_upstream_tags(ls_remote_output, prefix) -> Vector{VersionNumber}Versions of the refs/tags/<prefix>X.Y.Z tags in the output of git ls-remote --tags, sorted and unique. Peeled entries (^{}) and non-version tags are ignored.
UpstreamSync.imported_versions — Function
imported_versions(u; repo=nothing) -> Vector{VersionNumber}Versions of the upstream/X.Y.Z tags, read with git ls-remote --tags from repo (a path or URL) or, by default, from the GitHub repository.
UpstreamSync.parse_checksums — Function
parse_checksums(text) -> Dict{String,String}Parse a md5sum/sha256sum-style file (<hex> <file> or <hex> *<file> per line) into file => lower-case hex.
UpstreamSync.file_digest — Function
file_digest(path, algorithm) -> StringLower-case hexadecimal digest of a file (md5, sha1, sha256, sha512).
UpstreamSync.checksum_ok — Function
checksum_ok(path, expected, algorithm) -> BoolUpstreamSync.verify_checksum — Function
verify_checksum(path, filename, checksums, algorithm) -> StringCheck path against checksums[filename]; return the digest. Throws ChecksumMismatch on mismatch and UpstreamSyncError if filename has no published checksum.
UpstreamSync.fetch_text — Function
fetch_text(url) -> StringUpstreamSync.fetch_release — Function
fetch_release(u, version; cache, offline=false, io=stdout)Download (or reuse from the cache) the release tarball and the checksum file, and verify the checksum. The checksum file is always refreshed unless offline; a cached tarball that no longer matches is downloaded again once (upstream sometimes re-uploads a release under the same name). Returns (; url, path, filename, checksum).
UpstreamSync.extract_tarball — Function
extract_tarball(tarball, workdir) -> StringExtract with the system tar into a fresh directory below workdir and return the tarball's single top-level directory.
UpstreamSync.tarball_executables — Function
tarball_executables(tarball) -> Set{String}Regular files of the tarball (top directory stripped) whose owner execute bit is set in the tar header. The extracted files are not trusted for this: some file systems (ACL or network mounts) report every file as executable.
UpstreamSync.build_tree — Function
build_tree(repo, root, keep_paths, upstream_sha; executables=nothing)
-> (tree, dropped)Write a git tree with the exact bytes of every file below root (no .gitattributes/.gitignore/eol filtering), with the keep_paths taken from upstream_sha instead. File modes are 100755 for the paths in executables (default: the owner execute bit on disk). Uses a temporary index: the working tree and the real index of repo are not touched.
UpstreamSync.tag_message — Function
tag_message(u, version, import_message) -> StringThe message of the upstream/X.Y.Z tag: the source URL and checksum lines of the import commit message.
UpstreamSync.export_pathspecs — Function
export_pathspecs(u) -> Vector{String}Git pathspecs for "our fixes": export_paths minus export_exclude (git glob pathspecs, e.g. **/meson.build).
UpstreamSync.Area — Module
Area of the tree a file belongs to, used to group merge conflicts. Values: Area.BUILD, Area.SRC, Area.DOCS, Area.OTHER.
UpstreamSync.area_title — Function
area_title(area) -> StringUpstreamSync.pathmatch — Function
pathmatch(pattern, path) -> BoolMatch a repository path against a pattern:
dir/(trailing slash) matches everything belowdir/;- a pattern containing
/is a glob on the whole path (*,?,**); - a pattern without
/is a glob on the file name (meson.build,*.md), at any depth; - a leading
/anchors the pattern at the root (/configurematchesconfigureonly,/mk*matchesmkosxbut notsrc/mkfoo).
UpstreamSync.classify — Function
classify(path, areas) -> Area.TFirst area (in the order build, src, docs) with a matching pattern; Area.OTHER otherwise. areas maps "build", "src", "docs" to pattern lists (see pathmatch).
UpstreamSync.run_git — Function
run_git(args; dir=nothing, input=nothing, env=nothing) -> GitResultRun git [-C dir] args... without throwing, capturing stdout and stderr.
UpstreamSync.git — Function
git(repo, args...; input=nothing, env=nothing) -> StringRun git in repo; return stdout without the trailing newline; throw an UpstreamSyncError if git fails.
UpstreamSync.resolve_branch — Function
resolve_branch(repo, branch) -> (ref, sha)A local branch refs/heads/<branch>, or else refs/remotes/origin/<branch>.
UpstreamSync.check_not_stale — Function
check_not_stale(repo, branch, ref, sha; allow_stale=false, io=stdout,
remote="origin")Refuse to work from a local branch (resolved to ref at sha) that differs from the same branch on remote (read with git ls-remote), unless allow_stale. Without such a remote, or if the remote has no such branch, only a note is printed.
UpstreamSync.try_merge — Function
try_merge(repo, sync, import_ref, wt; keep=false, resolve=raw -> String[])
-> Vector{(path, code)}git merge --no-commit import_ref in a new worktree wt of branch sync and return the conflicted paths with their porcelain codes. Without keep the merge is aborted and the worktree removed. With keep, the paths returned by resolve(conflicts) are git rm-ed and the worktree is left with the merge in progress.
Returns (conflicts, added), added being the paths the merge adds to sync without a conflict. With keep, the paths returned by resolve(conflicts, added) are git rm-ed.
UpstreamSync.default_sync_worktree — Function
default_sync_worktree(u, version, repo) -> StringWhere merge-plan --resolve-expected leaves the merge: <repo>-sync-X.Y.Z next to the clone.
Errors
UpstreamSync.UpstreamSyncError — Type
UpstreamSyncError(msg)A user-facing error (bad configuration, missing branch, network failure, ...). The CLI prints the message and exits with status 1 (see ExitCode).
UpstreamSync.ChecksumMismatch — Type
ChecksumMismatch(file, algorithm, expected, actual)The downloaded file does not have the checksum published upstream.