Skip to content

Commit 362ff60

Browse files
author
Martin Vejnár
committed
Initial commit
0 parents  commit 362ff60

11 files changed

Lines changed: 420 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
include:
10+
- os: ubuntu-20.04
11+
pkg: DEB
12+
- os: windows-2019
13+
pkg: ZIP
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
submodules: true
21+
- uses: avakar/derive-version@v1
22+
id: version
23+
- name: Build
24+
run: |
25+
mkdir _build
26+
cd _build
27+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGITDEPTH_VERSION="${{ steps.version.outputs.version }}" -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_SHARED_LIBS=OFF
28+
cmake --build . --config RelWithDebInfo -j
29+
cpack -G ${{ matrix.pkg }} -C RelWithDebInfo
30+
- uses: actions/upload-artifact@v2
31+
if: matrix.pkg == 'ZIP'
32+
with:
33+
path: _build/*.zip

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_build/
2+
_output/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "deps/libgit2"]
2+
path = deps/libgit2
3+
url = https://github.com/libgit2/libgit2.git
4+
[submodule "deps/CLI11"]
5+
path = deps/CLI11
6+
url = https://github.com/CLIUtils/CLI11.git

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
set(GITDEPTH_VERSION "0.0.0" CACHE STRING "git-depth version number (major.minor.patch)")
4+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
5+
6+
project(avast.git-depth VERSION ${GITDEPTH_VERSION})
7+
8+
configure_file(
9+
src/git-depth.rc.in
10+
git-depth.rc)
11+
12+
include(FetchContent)
13+
FetchContent_Declare(libgit2
14+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/libgit2")
15+
FetchContent_Declare(CLI11 SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/CLI11")
16+
FetchContent_MakeAvailable(libgit2 CLI11)
17+
18+
add_executable(git-depth
19+
src/main.cpp
20+
${CMAKE_CURRENT_BINARY_DIR}/git-depth.rc
21+
)
22+
target_compile_features(git-depth PUBLIC cxx_std_17)
23+
target_include_directories(git-depth PUBLIC "${libgit2_SOURCE_DIR}/include")
24+
target_link_libraries(git-depth PUBLIC git2 CLI11::CLI11)
25+
26+
install(TARGETS git-depth)
27+
if (WIN32)
28+
install(FILES $<TARGET_PDB_FILE:git-depth> DESTINATION bin OPTIONAL)
29+
endif()

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Avast Software
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# git-depth
2+
3+
Computes depths of git revision graphs
4+
5+
## Motivation
6+
7+
In the days of Subversion, it was easy to derive version numbers from the Subversion revision number.
8+
Ever since distributed version control became the norm, this is no longer possible.
9+
Instead, a mechanism external to version control is typically used to allocate version numbers,
10+
which makes builds irreproducible.
11+
12+
This project proposes a different approach: the build number is derived from
13+
the structure of the git commit graph. Therefore, repeated builds starting at the same
14+
commit derive the same version number.
15+
16+
We guarantee that walking along a branch will produce strictly increasing
17+
numbers, except when one of the user-specified files change.
18+
In that case the version number resets.
19+
20+
Typically, this file will be a `VERSION` file containing the current major and minor version numbers.
21+
The result of `git-depth` can then be used as a patch number
22+
and appended to the contents of this file to produce a complete version.
23+
Incrementing major or minor version will automatically reset patch to zero.
24+
25+
## Getting Started
26+
27+
1. Download binaries from [releases][1] and place them somewhere in your path.
28+
2. Create your version file.
29+
30+
$ echo 1.0 >VERSION
31+
$ git add VERSION
32+
$ git commit -m "Add VERSION file"
33+
34+
3. Use `git-depth` to calculate the version patch number.
35+
36+
$ git-depth HEAD VERSION
37+
0
38+
39+
4. You can also automatically prepend the contents of the VERSION file.
40+
41+
$ git-depth -c HEAD VERSION
42+
1.0.0
43+
44+
4. Add more commits.
45+
46+
$ echo fix >>file.txt
47+
$ git commit -am "Fixes to file.txt"
48+
$ git-depth -c HEAD VERSION
49+
1.0.1
50+
$ echo the previous fix did not work >>file.txt
51+
$ git commit -am "More fixes to file.txt"
52+
$ git-depth -c HEAD VERSION
53+
1.0.2
54+
55+
5. Increase the minor version and observe the patch number reset.
56+
57+
$ echo 1.1 >VERSION
58+
$ git commit -am "Bump version to 1.1"
59+
$ git-depth -c HEAD VERSION
60+
1.1.0
61+
62+
## License
63+
64+
The project itself is licensed under the MIT license.
65+
However, the released binaries embed libgit2, which is licensed under GPL,
66+
and as such the binary releases are licensed as GPL a well.
67+
68+
[1]: https://github.com/avast/git-depth/releases

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2

deps/CLI11

Submodule CLI11 added at dd0d8e4

deps/libgit2

Submodule libgit2 added at 7d3c705

src/git-depth.rc.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <verrsrc.h>
2+
3+
VS_VERSION_INFO VERSIONINFO
4+
FILEVERSION ${avast.git-depth_VERSION_MAJOR},${avast.git-depth_VERSION_MINOR},0,${avast.git-depth_VERSION_PATCH}
5+
PRODUCTVERSION ${avast.git-depth_VERSION_MAJOR},${avast.git-depth_VERSION_MINOR},0,${avast.git-depth_VERSION_PATCH}
6+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
7+
#ifndef NDEBUG
8+
FILEFLAGS VS_FF_DEBUG
9+
#else
10+
FILEFLAGS 0
11+
#endif
12+
FILEOS VOS_NT_WINDOWS32
13+
FILETYPE VFT_APP
14+
FILESUBTYPE VFT2_UNKNOWN
15+
BEGIN
16+
END

0 commit comments

Comments
 (0)