From b3c9976e9c762f7806960fc9dbbfd834c03c91c7 Mon Sep 17 00:00:00 2001 From: praveensaummya Date: Wed, 10 Jun 2026 00:25:08 +0530 Subject: [PATCH 1/3] Add Termux support and improve installation scripts - Introduced a helper script for building gitstatusd and libgit2 on Termux. - Enhanced existing scripts to detect Android environments and provide installation guidance. - Updated Makefile to allow optional profiler libraries. --- Makefile | 3 ++- README.md | 13 ++++++++++ gitstatus.plugin.sh | 17 +++++++++--- install | 36 ++++++++++++++++++++++++-- scripts/termux-build.sh | 57 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 6 deletions(-) create mode 100755 scripts/termux-build.sh diff --git a/Makefile b/Makefile index 4a695ac..925c689 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ VERSION ?= $(shell . ./build.info && printf "%s" "$$gitstatus_version") # missing in macOS prior to 10.13. CXXFLAGS += -std=c++14 -funsigned-char -O3 -DNDEBUG -DGITSTATUS_VERSION=$(VERSION) # -Wall -g -fsanitize=thread LDFLAGS += -pthread # -fsanitize=thread -LDLIBS += -lgit2 # -lprofiler -lunwind +PROFILER_LIBS ?= +LDLIBS += -lgit2 $(PROFILER_LIBS) -lunwind SRCS := $(shell find src -name "*.cc") OBJS := $(patsubst src/%.cc, $(OBJDIR)/%.o, $(SRCS)) diff --git a/README.md b/README.md index 609d5f8..3a267af 100644 --- a/README.md +++ b/README.md @@ -513,6 +513,19 @@ cd gitstatus If everything goes well, the newly built binary will appear in `./usrbin`. It'll be picked up by shell bindings automatically. +### Termux (Android) + +On Android/Termux, prebuilt Linux binaries may be incompatible. This repository includes a helper +script to build `gitstatusd` in Termux. From the repository root run: + +```sh +bash scripts/termux-build.sh "$PWD" "$HOME/local" +``` + +The script installs required packages (ask for confirmation), builds a patched `libgit2` and +compiles `gitstatusd` into `./usrbin`. After a successful build, set `GITSTATUS_DAEMON` to +`/path/to/gitstatus/usrbin/gitstatusd` or let the installer detect it automatically. + When you update shell bindings, they may refuse to work with the binary you've built earlier. In this case you'll need to rebuild. diff --git a/gitstatus.plugin.sh b/gitstatus.plugin.sh index bfe16dc..3ad4e40 100644 --- a/gitstatus.plugin.sh +++ b/gitstatus.plugin.sh @@ -97,14 +97,25 @@ function gitstatus_start() { local uname_s="${uname_sm% *}" local uname_m="${uname_sm#* }" + if [[ "$uname_s" == linux ]]; then + local uname_a + if uname_a="$(command uname -a 2>/dev/null)" && [[ "$uname_a" == *Android* ]]; then + uname_s=android + fi + fi + if [[ "${GITSTATUS_NUM_THREADS:-0}" -gt 0 ]]; then local threads="$GITSTATUS_NUM_THREADS" else local cpus if ! command -v sysctl &>/dev/null || [[ "$uname_s" == linux ]] || - ! cpus="$(command sysctl -n hw.ncpu)"; then - if ! command -v getconf &>/dev/null || ! cpus="$(command getconf _NPROCESSORS_ONLN)"; then - cpus=8 + ! cpus="$(command sysctl -n hw.ncpu 2>/dev/null)"; then + if ! command -v getconf &>/dev/null || ! cpus="$(command getconf _NPROCESSORS_ONLN 2>/dev/null)"; then + if command -v nproc &>/dev/null && nproc >/dev/null 2>&1; then + cpus="$(command nproc)" + else + cpus=8 + fi fi fi local threads=$((cpus > 16 ? 32 : cpus > 0 ? 2 * cpus : 16)) diff --git a/install b/install index 76f339e..ee6b4c0 100755 --- a/install +++ b/install @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # # This script does not have a stable API. @@ -142,6 +142,13 @@ END uname_m="$(printf '%s' "$uname_m" | command tr '[A-Z]' '[a-z]')" || return fi + if [ "$uname_s" = linux ]; then + local uname_a + if uname_a="$(command uname -a 2>/dev/null)" && [ "${uname_a#*Android}" != "$uname_a" ]; then + uname_s=android + fi + fi + local daemon="${GITSTATUS_DAEMON:-}" local cache_dir="${GITSTATUS_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/gitstatus}" @@ -465,6 +472,31 @@ END >&"$e" printf 'There is no prebuilt \033[32mgitstatusd\033[0m for \033[1m%s\033[0m.\n' "$uname_s $uname_m" >&"$e" printf '\n' + if [ "$uname_s" = android ]; then + >&"$e" printf 'Android support for this architecture requires a locally built gitstatusd.\n' + >&"$e" printf 'Build from source and set \033[32mGITSTATUS_DAEMON\033[0m to the executable.\n' + >&"$e" printf '\n' + # If the Termux helper script exists, offer to run it interactively + if [ -x "$gitstatus_dir/scripts/termux-build.sh" ] && [ -t 0 ]; then + >&"$e" printf 'This repository includes a Termux build helper: %s/scripts/termux-build.sh\n' "$gitstatus_dir" + >&"$e" printf 'Would you like to run it now to build gitstatusd locally? [Y/n] ' + IFS= read -r _ans || _ans=n + case "$_ans" in + ''|[Yy]|[Yy][Ee][Ss]) + command chmod +x -- "$gitstatus_dir/scripts/termux-build.sh" 2>/dev/null || true + if bash "$gitstatus_dir/scripts/termux-build.sh" "$gitstatus_dir" "$HOME/local"; then + if [ -x "$gitstatus_dir/usrbin/gitstatusd" ]; then + daemon="$gitstatus_dir/usrbin/gitstatusd" + _gitstatus_install_daemon_found 1 "$@" + return + fi + fi + ;; + *) ;; + esac + >&"$e" printf '\n' + fi + fi >&"$e" printf 'See: \033[4mhttps://github.com/romkatv/gitstatus#compiling\033[0m\n' return 1 } @@ -473,4 +505,4 @@ if [ -z "${0##*/*}" ]; then _gitstatus_install_main "${0%/*}" "$@" else _gitstatus_install_main . "$@" -fi +fi \ No newline at end of file diff --git a/scripts/termux-build.sh b/scripts/termux-build.sh new file mode 100755 index 0000000..62eeac3 --- /dev/null +++ b/scripts/termux-build.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Termux automation script for building libgit2 and gitstatusd +# Usage: ./scripts/termux-build.sh [REPO_DIR] [INSTALL_PREFIX] +# Defaults: REPO_DIR=$PWD, INSTALL_PREFIX=$HOME/local + +REPO_DIR="${1:-$PWD}" +PREFIX="${2:-$HOME/local}" + +echo "Repo: $REPO_DIR" +echo "Install prefix: $PREFIX" + +echo "Installing Termux packages..." +pkg update -y +pkg install -y git clang cmake make autoconf automake libtool pkg-config \ + bash curl tar unzip coreutils openssl zlib + +mkdir -p "$PREFIX" + +# Build patched libgit2 (romkatv/libgit2) +LG2_SRC="$HOME/libgit2" +if [ ! -d "$LG2_SRC" ]; then + echo "Cloning romkatv/libgit2 into $LG2_SRC" + git clone https://github.com/romkatv/libgit2.git "$LG2_SRC" +fi + +echo "Building libgit2..." +mkdir -p "$LG2_SRC/build" +cd "$LG2_SRC/build" +cmake -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_CLAR=OFF \ + -DUSE_SSH=OFF \ + -DCMAKE_INSTALL_PREFIX="$PREFIX" .. +make -j"$(nproc)" +make install + +export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:${PKG_CONFIG_PATH:-}" +export LD_LIBRARY_PATH="$PREFIX/lib:${LD_LIBRARY_PATH:-}" + +# Build gitstatusd +echo "Building gitstatusd in $REPO_DIR" +cd "$REPO_DIR" +make clean || true +make CXX=clang++ \ + CXXFLAGS="-I$PREFIX/include" \ + LDFLAGS="-L$PREFIX/lib" \ + LDLIBS="-lgit2 -lcrypto -lssl -lz -lunwind" + +echo +echo "Build finished. If successful, the binary is at: $REPO_DIR/usrbin/gitstatusd" +echo "To run from Termux (example):" +echo " export GITSTATUS_DAEMON=\"$REPO_DIR/usrbin/gitstatusd\"" +echo " bash -ic 'cd \"$REPO_DIR\" && source ./gitstatus.plugin.sh && gitstatus_start -t 5'" + +exit 0 From e74b7fe2a219533dce794ec434089291b7f63cc2 Mon Sep 17 00:00:00 2001 From: praveensaummya Date: Wed, 10 Jun 2026 07:35:42 +0530 Subject: [PATCH 2/3] Enhance Termux build script and README for improved installation process --- README.md | 48 +++++++++++++++++++++++++++++++++++++---- scripts/termux-build.sh | 11 ++++++++-- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3a267af..dc6d4bb 100644 --- a/README.md +++ b/README.md @@ -522,9 +522,49 @@ script to build `gitstatusd` in Termux. From the repository root run: bash scripts/termux-build.sh "$PWD" "$HOME/local" ``` -The script installs required packages (ask for confirmation), builds a patched `libgit2` and -compiles `gitstatusd` into `./usrbin`. After a successful build, set `GITSTATUS_DAEMON` to -`/path/to/gitstatus/usrbin/gitstatusd` or let the installer detect it automatically. +The script: +- Installs required Termux packages +- Builds a patched `libgit2` from `romkatv/libgit2` +- Compiles `gitstatusd` with the correct version flag +- Produces the binary in `./usrbin` + +After a successful build, set `GITSTATUS_DAEMON` to point to it: + +```sh +export GITSTATUS_DAEMON="$HOME/gitstatus/usrbin/gitstatusd" +source "$HOME/gitstatus/gitstatus.plugin.zsh" +gitstatus_start -t 5 MY +``` + +Or add to `~/.zshrc` to auto-start gitstatus in every shell. + +```sh +export GITSTATUS_DAEMON="$HOME/gitstatus/usrbin/gitstatusd" +source "$HOME/gitstatus/gitstatus.plugin.zsh" +gitstatus_stop MY 2>/dev/null || true +gitstatus_start -t 5 MY +``` + +**Manual build (if not using the helper script):** + +```sh +# Build libgit2 first +git clone https://github.com/romkatv/libgit2.git ~/libgit2 +cd ~/libgit2 && mkdir build && cd build +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DUSE_SSH=OFF -DCMAKE_INSTALL_PREFIX="$HOME/local" .. +make -j$(nproc) && make install + +# Build gitstatus +export PKG_CONFIG_PATH="$HOME/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" +export LD_LIBRARY_PATH="$HOME/local/lib:${LD_LIBRARY_PATH:-}" +cd ~/gitstatus +make clean +make CXX=clang++ \ + CXXFLAGS="-I$HOME/local/include -DGITSTATUS_VERSION=v1.5.5" \ + LDFLAGS="-L$HOME/local/lib" \ + LDLIBS="-lgit2 -lcrypto -lssl -lz -lunwind" \ + -j8 +``` When you update shell bindings, they may refuse to work with the binary you've built earlier. In this case you'll need to rebuild. @@ -544,4 +584,4 @@ gitstatus are released. This may change in the future but not soon. ## License GNU General Public License v3.0. See [LICENSE](LICENSE). Contributions are covered by the same -license. +license. \ No newline at end of file diff --git a/scripts/termux-build.sh b/scripts/termux-build.sh index 62eeac3..c5ae859 100755 --- a/scripts/termux-build.sh +++ b/scripts/termux-build.sh @@ -42,9 +42,16 @@ export LD_LIBRARY_PATH="$PREFIX/lib:${LD_LIBRARY_PATH:-}" # Build gitstatusd echo "Building gitstatusd in $REPO_DIR" cd "$REPO_DIR" + +# Extract version from build.info +local version= +if [ -f build.info ]; then + version="$(grep '^gitstatus_version=' build.info | cut -d= -f2)" +fi + make clean || true make CXX=clang++ \ - CXXFLAGS="-I$PREFIX/include" \ + CXXFLAGS="-I$PREFIX/include${version:+ -DGITSTATUS_VERSION=$version}" \ LDFLAGS="-L$PREFIX/lib" \ LDLIBS="-lgit2 -lcrypto -lssl -lz -lunwind" @@ -54,4 +61,4 @@ echo "To run from Termux (example):" echo " export GITSTATUS_DAEMON=\"$REPO_DIR/usrbin/gitstatusd\"" echo " bash -ic 'cd \"$REPO_DIR\" && source ./gitstatus.plugin.sh && gitstatus_start -t 5'" -exit 0 +exit 0 \ No newline at end of file From 5372b6b9c84640cd9a37858f24adbedf7e5e214b Mon Sep 17 00:00:00 2001 From: praveensaummya Date: Wed, 10 Jun 2026 18:38:35 +0530 Subject: [PATCH 3/3] Update Termux build script to extract version from build.info and install binary to PREFIX/bin --- README.md | 145 +++++++++++++++++++--------------------- scripts/termux-build.sh | 15 +++-- 2 files changed, 79 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index dc6d4bb..3d2fd8c 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ Bash bindings for integration with shell. ## Table of Contents 1. [Using from Zsh](#using-from-zsh) -1. [Using from Bash](#using-from-bash) -2. [Using from other shells](#using-from-other-shells) -1. [How it works](#how-it-works) -1. [Benchmarks](#benchmarks) -1. [Why fast](#why-fast) -1. [Requirements](#requirements) -1. [Compiling](#compiling) -1. [License](#license) +2. [Using from Bash](#using-from-bash) +3. [Using from other shells](#using-from-other-shells) +4. [How it works](#how-it-works) +5. [Benchmarks](#benchmarks) +6. [Why fast](#why-fast) +7. [Requirements](#requirements) +8. [Compiling](#compiling) +9. [License](#license) ## Using from Zsh @@ -29,8 +29,7 @@ with it. For example, [Powerlevel10k](https://github.com/romkatv/powerlevel10k) fast theme with first-class gitstatus integration. If you install Powerlevel10k, you don't need to install gitstatus. -![Powerlevel10k Zsh Theme]( - https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/prompt-styles-high-contrast.png) +![Powerlevel10k Zsh Theme](https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/prompt-styles-high-contrast.png) For those who wish to use gitstatus without a theme, there is [gitstatus.prompt.zsh](gitstatus.prompt.zsh). Install it as follows: @@ -40,7 +39,7 @@ git clone --depth=1 https://github.com/romkatv/gitstatus.git ~/gitstatus echo 'source ~/gitstatus/gitstatus.prompt.zsh' >>! ~/.zshrc ``` -Users in China can use the official mirror on gitee.com for faster download.
+Users in China can use the official mirror on gitee.com for faster download.`
` 中国大陆用户可以使用 gitee.com 上的官方镜像加速下载. ```zsh @@ -74,21 +73,21 @@ RPROMPT='$GITSTATUS_PROMPT' # right prompt: git status The expansion of `${GITSTATUS_PROMPT}` can contain the following bits: -| segment | meaning | -|-------------|-------------------------------------------------------| -| `master` | current branch | -| `#v1` | HEAD is tagged with `v1`; not shown when on a branch | -| `@5fc6fca4` | current commit; not shown when on a branch or tag | -| `⇣1` | local branch is behind the remote by 1 commit | -| `⇡2` | local branch is ahead of the remote by 2 commits | -| `⇠3` | local branch is behind the push remote by 3 commits | -| `⇢4` | local branch is ahead of the push remote by 4 commits | -| `*5` | there are 5 stashes | -| `merge` | merge is in progress (could be some other action) | -| `~6` | there are 6 merge conflicts | -| `+7` | there are 7 staged changes | -| `!8` | there are 8 unstaged changes | -| `?9` | there are 9 untracked files | +| segment | meaning | +| ------------- | ------------------------------------------------------ | +| `master` | current branch | +| `#v1` | HEAD is tagged with `v1`; not shown when on a branch | +| `@5fc6fca4` | current commit; not shown when on a branch or tag | +| `⇣1` | local branch is behind the remote by 1 commit | +| `⇡2` | local branch is ahead of the remote by 2 commits | +| `⇠3` | local branch is behind the push remote by 3 commits | +| `⇢4` | local branch is ahead of the push remote by 4 commits | +| `*5` | there are 5 stashes | +| `merge` | merge is in progress (could be some other action) | +| `~6` | there are 6 merge conflicts | +| `+7` | there are 7 staged changes | +| `!8` | there are 8 unstaged changes | +| `?9` | there are 9 untracked files | `$GITSTATUS_PROMPT_LEN` tells you how long `$GITSTATUS_PROMPT` is when printed to the console. [gitstatus.prompt.zsh](gitstatus.prompt.zsh) has an example of using it to truncate the current @@ -141,7 +140,7 @@ git clone --depth=1 https://github.com/romkatv/gitstatus.git ~/gitstatus echo 'source ~/gitstatus/gitstatus.prompt.sh' >> ~/.bashrc ``` -Users in China can use the official mirror on gitee.com for faster download.
+Users in China can use the official mirror on gitee.com for faster download.`
` 中国大陆用户可以使用 gitee.com 上的官方镜像加速下载. ```bash @@ -162,8 +161,7 @@ in all code snippets below.) This will give you a basic yet functional prompt with git status in it. It's [over 10x faster](#benchmarks) than any alternative that can give you comparable prompt. -![Bash Prompt with GitStatus]( - https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/bash-prompt.png) +![Bash Prompt with GitStatus](https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/bash-prompt.png) In order to customize your prompt, set `PS1` at the end of `~/.bashrc` after sourcing `gitstatus.prompt.sh`. Insert `${GITSTATUS_PROMPT}` where you want git status to go. For example: @@ -176,21 +174,21 @@ PS1='\w ${GITSTATUS_PROMPT}\n\$ ' # directory followed by git status and $/# (no The expansion of `${GITSTATUS_PROMPT}` can contain the following bits: -| segment | meaning | -|-------------|-------------------------------------------------------| -| `master` | current branch | -| `#v1` | HEAD is tagged with `v1`; not shown when on a branch | -| `@5fc6fca4` | current commit; not shown when on a branch or tag | -| `⇣1` | local branch is behind the remote by 1 commit | -| `⇡2` | local branch is ahead of the remote by 2 commits | -| `⇠3` | local branch is behind the push remote by 3 commits | -| `⇢4` | local branch is ahead of the push remote by 4 commits | -| `*5` | there are 5 stashes | -| `merge` | merge is in progress (could be some other action) | -| `~6` | there are 6 merge conflicts | -| `+7` | there are 7 staged changes | -| `!8` | there are 8 unstaged changes | -| `?9` | there are 9 untracked files | +| segment | meaning | +| ------------- | ------------------------------------------------------ | +| `master` | current branch | +| `#v1` | HEAD is tagged with `v1`; not shown when on a branch | +| `@5fc6fca4` | current commit; not shown when on a branch or tag | +| `⇣1` | local branch is behind the remote by 1 commit | +| `⇡2` | local branch is ahead of the remote by 2 commits | +| `⇠3` | local branch is behind the push remote by 3 commits | +| `⇢4` | local branch is ahead of the push remote by 4 commits | +| `*5` | there are 5 stashes | +| `merge` | merge is in progress (could be some other action) | +| `~6` | there are 6 merge conflicts | +| `+7` | there are 7 staged changes | +| `!8` | there are 8 unstaged changes | +| `?9` | there are 9 untracked files | If you'd like to change the format of git status, or want to have greater control over the process of assembling `PS1`, you can copy and modify parts of @@ -278,11 +276,11 @@ Two commands were benchmarked: `status` and `describe`. In this benchmark all tools were computing the equivalent of `git status`. Lower numbers are better. -| Tool | Cold | Hot | -|---------------|-----------:|------------:| +| Tool | Cold | Hot | +| ------------------- | ---------------: | ----------------: | | **gitstatus** | **291 ms** | **30.9 ms** | -| git | 876 ms | 295 ms | -| lg2 | 1730 ms | 1310 ms | +| git | 876 ms | 295 ms | +| lg2 | 1730 ms | 1310 ms | gitstatusd is substantially faster than the alternatives, especially on hot runs. Note that hot runs are of primary importance to the main use case of gitstatus in interactive shells. @@ -298,11 +296,11 @@ shown. In this benchmark all tools were computing the equivalent of `git describe --tags --exact-match` to find tags that resolve to the same commit as `HEAD`. Lower numbers are better. -| Tool | Cold | Hot | -|---------------|------------:|--------------:| +| Tool | Cold | Hot | +| ------------------- | ----------------: | ------------------: | | **gitstatus** | **4.04 ms** | **0.0345 ms** | -| git | 18.0 ms | 14.5 ms | -| lg2 | 185 ms | 45.2 ms | +| git | 18.0 ms | 14.5 ms | +| lg2 | 185 ms | 45.2 ms | gitstatusd is once again faster than the alternatives, more so on hot runs. @@ -329,11 +327,11 @@ Under the benchmark conditions described above, the equivalent of libgit2's gitstatusd. The speedup comes from the following sources. * gitstatusd uses more efficient data structures and algorithms and employs performance-conscious -coding style throughout the codebase. This reduces CPU time in userspace by 32x compared to libgit2. + coding style throughout the codebase. This reduces CPU time in userspace by 32x compared to libgit2. * gitstatusd uses less expensive system calls and makes fewer of them. This reduces CPU time spent -in kernel by 1.9x. + in kernel by 1.9x. * gitstatusd can utilize multiple cores to scan index and workdir in parallel with almost perfect -scaling. This reduces total run time by 12.4x while having virtually no effect on total CPU time. + scaling. This reduces total run time by 12.4x while having virtually no effect on total CPU time. ### Problem statement @@ -343,7 +341,7 @@ repository with their last modification times. This is an obvious simplification this exposition. On disk, index is stored sorted by file path. Here's an example of git index: | File | Last modification time | -|-------------|-----------------------:| +| ----------- | ---------------------: | | Makefile | 2019-04-01T14:12:32Z | | src/hello.c | 2019-04-01T14:12:00Z | | src/hello.h | 2019-04-01T14:12:32Z | @@ -363,8 +361,7 @@ form of work directory traversal. Let's see how `git_diff_index_to_workdir` from libgit2 accomplishes these tasks. Here's its CPU profile from 200 hot runs over chromium repository. -![libgit2 CPU profile (hot)]( - https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-libgit2.png) +![libgit2 CPU profile (hot)](https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-libgit2.png) (The CPU profile was created with [gperftools](https://github.com/gperftools/gperftools) and rendered with [pprof](https://github.com/google/pprof)). @@ -377,8 +374,7 @@ strings, sorting arrays, etc. Now let's take a look at the CPU profile of gitstatusd on the same task. -![gitstatusd CPU profile (hot)]( - https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-gitstatusd-hot.png) +![gitstatusd CPU profile (hot)](https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-gitstatusd-hot.png) The first impression is that this profile looks pruned. This isn't an artifact. The profile was generated with the same tools and the same flags as the profile of libgit2. @@ -433,8 +429,7 @@ To summarize, here's what gitstatusd was doing when the CPU profile was captured Here's how the very first scan of a repository looks like in gitstatusd: -![gitstatusd CPU profile (cold)]( - https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-gitstatusd-cold.png) +![gitstatusd CPU profile (cold)](https://raw.githubusercontent.com/romkatv/gitstatus/1ac366952366d89980b3f3484f270b4fa5ae4293/cpu-profile-gitstatusd-cold.png) (Some glibc functions are mislabel on this profile. `explicit_bzero` and `__nss_passwd_lookup` are in reality `strcmp` and `memcmp`.) @@ -482,8 +477,7 @@ _WARNING: Changes to libgit2 are extensive but the testing they underwent isn't. ## Compiling -There are prebuilt `gitstatusd` binaries in [releases]( - https://github.com/romkatv/gitstatus/releases). When using the official shell bindings +There are prebuilt `gitstatusd` binaries in [releases](https://github.com/romkatv/gitstatus/releases). When using the official shell bindings provided by gitstatus, the right binary for your architecture gets downloaded automatically. If prebuilt binaries don't work for you, you'll need to get your hands dirty. @@ -496,7 +490,7 @@ cd gitstatus ./build -w -s -d docker ``` -Users in China can use the official mirror on gitee.com for faster download.
+Users in China can use the official mirror on gitee.com for faster download.`
` 中国大陆用户可以使用 gitee.com 上的官方镜像加速下载. ```zsh @@ -523,28 +517,25 @@ bash scripts/termux-build.sh "$PWD" "$HOME/local" ``` The script: + - Installs required Termux packages - Builds a patched `libgit2` from `romkatv/libgit2` -- Compiles `gitstatusd` with the correct version flag +- Compiles `gitstatusd` with the correct version flag from `build.info` - Produces the binary in `./usrbin` +- Installs the binary to `$HOME/local/bin/gitstatusd` -After a successful build, set `GITSTATUS_DAEMON` to point to it: - -```sh -export GITSTATUS_DAEMON="$HOME/gitstatus/usrbin/gitstatusd" -source "$HOME/gitstatus/gitstatus.plugin.zsh" -gitstatus_start -t 5 MY -``` - -Or add to `~/.zshrc` to auto-start gitstatus in every shell. +After a successful build, make the install permanent by exporting the binary path in your shell startup and sourcing the plugin: ```sh -export GITSTATUS_DAEMON="$HOME/gitstatus/usrbin/gitstatusd" +export PATH="$HOME/local/bin:$PATH" +export GITSTATUS_DAEMON="$HOME/local/bin/gitstatusd" source "$HOME/gitstatus/gitstatus.plugin.zsh" gitstatus_stop MY 2>/dev/null || true gitstatus_start -t 5 MY ``` +Add that block to `~/.zshrc` or `~/.bashrc` to keep the build available in every shell. + **Manual build (if not using the helper script):** ```sh @@ -584,4 +575,4 @@ gitstatus are released. This may change in the future but not soon. ## License GNU General Public License v3.0. See [LICENSE](LICENSE). Contributions are covered by the same -license. \ No newline at end of file +license. diff --git a/scripts/termux-build.sh b/scripts/termux-build.sh index c5ae859..867d260 100755 --- a/scripts/termux-build.sh +++ b/scripts/termux-build.sh @@ -44,21 +44,28 @@ echo "Building gitstatusd in $REPO_DIR" cd "$REPO_DIR" # Extract version from build.info -local version= +version= if [ -f build.info ]; then - version="$(grep '^gitstatus_version=' build.info | cut -d= -f2)" + . ./build.info + version="$gitstatus_version" fi make clean || true make CXX=clang++ \ CXXFLAGS="-I$PREFIX/include${version:+ -DGITSTATUS_VERSION=$version}" \ LDFLAGS="-L$PREFIX/lib" \ - LDLIBS="-lgit2 -lcrypto -lssl -lz -lunwind" + LDLIBS="-lgit2 -lcrypto -lssl -lz -lunwind" \ + -j"$(nproc)" + +install -d "$PREFIX/bin" +install -m 755 "$REPO_DIR/usrbin/gitstatusd" "$PREFIX/bin/gitstatusd" echo echo "Build finished. If successful, the binary is at: $REPO_DIR/usrbin/gitstatusd" +echo "Installed copy to: $PREFIX/bin/gitstatusd" echo "To run from Termux (example):" -echo " export GITSTATUS_DAEMON=\"$REPO_DIR/usrbin/gitstatusd\"" +echo " export PATH=\"$PREFIX/bin:\$PATH\"" +echo " export GITSTATUS_DAEMON=\"$PREFIX/bin/gitstatusd\"" echo " bash -ic 'cd \"$REPO_DIR\" && source ./gitstatus.plugin.sh && gitstatus_start -t 5'" exit 0 \ No newline at end of file