Skip to content

Commit 002afca

Browse files
committed
version 0.1
1 parent cbfefe3 commit 002afca

8 files changed

Lines changed: 465 additions & 1208 deletions

File tree

Makefile

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
appname := gitstatus
2-
3-
CXX := g++
4-
5-
CXXFLAGS := \
6-
-std=c++17 \
7-
-funsigned-char \
8-
-fmax-errors=1 \
9-
-O3 \
10-
-g \
11-
-DNDEBUG
12-
13-
LDFLAGS := \
14-
-static-libstdc++ \
15-
-static-libgcc \
16-
-pthread \
17-
-l:libgit2.a \
18-
-l:libssl.a \
19-
-l:libcrypto.a \
20-
-l:libz.a \
21-
-ldl
1+
APPNAME ?= gitstatus
2+
3+
CXX ?= g++
4+
5+
CXXFLAGS += -std=c++17 -funsigned-char -fno-exceptions -O3 -DNDEBUG -Wall -Werror
6+
LDFLAGS += -static -s
7+
8+
CXXFLAGS += $(shell pkg-config --cflags libgit2)
9+
LDFLAGS += $(shell pkg-config --libs libgit2)
2210

2311
SRCS := $(shell find src -name "*.cc")
2412
OBJS := $(patsubst src/%.cc, obj/%.o, $(SRCS))
2513

26-
all: $(appname)
14+
all: $(APPNAME)
2715

28-
$(appname): $(OBJS)
29-
$(CXX) $(OBJS) $(LDFLAGS) -o $(appname)
16+
$(APPNAME): $(OBJS)
17+
$(CXX) $(OBJS) $(LDFLAGS) -o $(APPNAME)
3018

3119
obj:
3220
mkdir -p obj

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# gitstatus
2+
**gitstatus** is a lightweight tool for querying the status of git repos for the use in interactive tools.
3+
4+
The primary motivation is to be able to use git status in shell prompt without suffering terrible latency that all other solutions impose.
5+
6+
When using common tools such as [vcs_info](http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#vcs_005finfo-Quickstart) to embed git status in shell prompt, latency is high for two main reasons:
7+
8+
1. About a dozen processes are created to generate a prompt. Creating processes and pipes to communicate with them is expensive.
9+
2. There is a lot of redundancy between different `git` commands that get called. For example, every command has to scan parent directories in search of `.git`. Many commands have to resolve HEAD. Some have to read index.
10+
11+
**gitstatus** solves this problem by assembling all information that the prompt needs in a single process and presenting it in an easy-to-parse format. It's using [libgit2](https://libgit2.org/) under the hood for heavy lifting.
12+
13+
## Requirements
14+
15+
* To compile: C++17 compiler, GNU make, libgit2.
16+
* To run: Linux, GNU libc.
17+
18+
## Compiling
19+
20+
For best results, compile libgit2 statically with all optional features disabled and all required feature bundled.
21+
22+
```shell
23+
git clone https://github.com/libgit2/libgit2.git
24+
cd libgit2
25+
mkdir build
26+
cd build
27+
cmake \
28+
-DUSE_SSH=OFF \
29+
-DUSE_HTTPS=OFF \
30+
-DTHREADSAFE=OFF \
31+
-DBUILD_SHARED_LIBS=OFF \
32+
-DUSE_EXT_HTTP_PARSER=OFF \
33+
-DUSE_BUNDLED_ZLIB=ON \
34+
-DSHA1_BACKEND=Generic \
35+
-DCMAKE_BUILD_TYPE=Release \
36+
..
37+
make VERBOSE=1 -j 20
38+
sudo make install
39+
```
40+
41+
Then build gitstatus itself.
42+
43+
```shell
44+
git clone git@github.com:romkatv/gitstatus.git
45+
cd gitstatus
46+
make
47+
```
48+
49+
## Prebuilt Binaries
50+
51+
If you don't feel like building from sources, you can grab a statically built ELF binary for x64 with a dynamic dependency on glibc 6 from [Releases](https://github.com/romkatv/gitstatus/releases).
52+
53+
## Using Manually
54+
55+
Run `gitstatus --help` for help or read the same thing in [gitstatus.cc](https://github.com/romkatv/gitstatus/blob/master/src/gitstatus.cc).
56+
57+
## Using with Powerlevel9k
58+
59+
If you are using the awesome [Powerlevel9k](https://github.com/bhilburn/powerlevel9k) ZSH theme, you can configure the existing `vcs` prompt to use gitstatus for a massive reduction in latency.
60+
61+
First, use [this fork](https://github.com/romkatv/powerlevel9k/tree/caching) of Powerlevel9k instead of the official release. This fork also enables caching, which speeds up prompt rendering by over 10x. Note that you need to use branch `caching`.
62+
63+
```shell
64+
# Assuming oh-my-zsh at the standard location.
65+
rm -rf ~/.oh-my-zsh/custom/themes/powerlevel9k
66+
git clone -b caching git@github.com:romkatv/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
67+
```
68+
69+
Then set the following configuration options in your `.zshrc` before sourcing Powerlevel9k.
70+
71+
```
72+
# Enable caching of parts of the prompt to make rendering much faster.
73+
POWERLEVEL9K_USE_CACHE=true
74+
75+
# Enable alternative implementation for the vcs prompt. It's much faster but it only supports git.
76+
# Tell it to not scan for dirty files in repos with over 1k files.
77+
POWERLEVEL9K_VCS_STATUS_COMMAND="$HOME/bin/gitstatus --dirty-max-index-size=1024"
78+
```
79+
80+
Lastly, put `gitstatus` binary in your `~/bin`.
81+
82+
You can check out my [dotfiles-public](https://github.com/romkatv/dotfiles-public) repo for details.
83+
84+
## License
85+
86+
GNU General Public License v3.0. See [LICENSE](https://github.com/romkatv/gitstatus/blob/master/LICENSE).

src/check.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
// Copyright 2018 Roman Perepelitsa
1+
// Copyright 2018 Roman Perepelitsa.
22
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
3+
// This file is part of GitStatus.
64
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
5+
// GitStatus is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
89
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
10+
// GitStatus is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with GitStatus. If not, see <https://www.gnu.org/licenses/>.
1417

15-
#ifndef ROMKATV_HCPROXY_CHECK_H_
16-
#define ROMKATV_HCPROXY_CHECK_H_
18+
#ifndef ROMKATV_GITSTATUS_CHECK_H_
19+
#define ROMKATV_GITSTATUS_CHECK_H_
1720

1821
#include "logging.h"
1922

@@ -23,4 +26,4 @@
2326
#define CHECK(cond...) \
2427
static_cast<void>(0), (!!(cond)) ? static_cast<void>(0) : LOG(FATAL) << #cond << ": "
2528

26-
#endif // ROMKATV_HCPROXY_CHECK_H_
29+
#endif // ROMKATV_GITSTATUS_CHECK_H_

0 commit comments

Comments
 (0)