Skip to content

Serialized Git Commit Graph

Derrick Stolee git 8 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest14 patches 9 repliesIn review
  2. v714 patches 10 repliesSuperseded
  3. v614 patches 26 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v513 patches6 repliesSuperseded
v413 patches44 repliesSuperseded
v314 patches24 repliesSuperseded
v214 patches34 repliesSuperseded
v114 patches34 repliesSuperseded

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14csum-file: rename hashclose() to finalize_hashfile()builtin/index-pack.c builtin/pack-objects.c bulk-checkin.c +5 more+13 -130 replies
2/14csum-file: refactor finalize_hashfile() methodbuiltin/pack-objects.c bulk-checkin.c csum-file.c +3 more+14 -120 replies
3/14commit-graph: add format documentDocumentation/technical/commit-graph-format.txt+97 -05 replies
4/14graph: add commit graph design documentDocumentation/technical/commit-graph.txt+163 -01 reply
5/14commit-graph: create git-commit-graph builtin.gitignore Documentation/git-commit-graph.txt Makefile +5 more+53 -00 replies
6/14commit-graph: implement write_commit_graph()Makefile commit-graph.c commit-graph.h+366 -00 replies
7/14commit-graph: implement git-commit-graph writeDocumentation/git-commit-graph.txt builtin/commit-graph.c t/t5318-commit-graph.sh+198 -00 replies
8/14commit-graph: implement git commit-graph readDocumentation/git-commit-graph.txt builtin/commit-graph.c commit-graph.c +2 more+254 -62 replies
9/14commit-graph: add core.commitGraph settingDocumentation/config.txt cache.h config.c +1 more+11 -01 reply
10/14commit-graph: close under reachabilitycommit-graph.c+45 -00 replies
11/14commit: integrate commit graph with commit parsingalloc.c commit-graph.c commit-graph.h +3 more+205 -20 replies
12/14commit-graph: read only from specific pack-indexesDocumentation/git-commit-graph.txt builtin/commit-graph.c commit-graph.c +4 more+81 -90 replies
13/14commit-graph: build graph from starting commitsDocumentation/git-commit-graph.txt builtin/commit-graph.c commit-graph.c +2 more+75 -100 replies
14/14commit-graph: implement "--append" optionDocumentation/git-commit-graph.txt builtin/commit-graph.c commit-graph.c +2 more+45 -50 replies

Reviews trailers per patch

None of the 14 patches has a Reviewed-by or Acked-by.

PatchJeff King
1/14
2/14
3/14
4/14
5/14
6/14Helped-by
7/14
8/14
9/14
10/14
11/14
12/14
13/14
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH v8 00/14] Serialized Git Commit Graph

This version covers the review that I missed when rerolling v7. The file diff is below from previous version, and also PATCH 14/14 was reworded to use "--append" properly.

builtin/commit-graph.c +1 -1
index 41c4f76caf..37420ae0fd 100644
@@ -31,7 +31,7 @@ static struct opts_commit_graph {
 
 static int graph_read(int argc, const char **argv)
 {
-       struct commit_graph *graph = 0;
+       struct commit_graph *graph = NULL;
        char *graph_name;
 
        static struct option builtin_commit_graph_read_options[] = {
commit-graph.c +1 -1
index 1fc63d541b..3ff8c84c0e 100644
@@ -179,7 +179,7 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
 }
 
 /* global storage */
-struct commit_graph *commit_graph = NULL;
+static struct commit_graph *commit_graph = NULL;
 
 static void prepare_commit_graph_one(const char *obj_dir)
 {

-- >8 --

This patch contains a way to serialize the commit graph.

The current implementation defines a new file format to store the graph structure (parent relationships) and basic commit metadata (commit date, root tree OID) in order to prevent parsing raw commits while performing basic graph walks. For example, we do not need to parse the full commit when performing these walks:

* 'git log --topo-order -1000' walks all reachable commits to avoid incorrect topological orders, but only needs the commit message for the top 1000 commits.

* 'git merge-base <A> <B>' may walk many commits to find the correct boundary between the commits reachable from A and those reachable from B. No commit messages are needed.

* 'git branch -vv' checks ahead/behind status for all local branches compared to their upstream remote branches. This is essentially as hard as computing merge bases for each.

The current patch speeds up these calculations by injecting a check in parse_commit_gently() to check if there is a graph file and using that to provide the required metadata to the struct commit.

The file format has room to store generation numbers, which will be provided as a patch after this framework is merged. Generation numbers are referenced by the design document but not implemented in order to make the current patch focus on the graph construction process. Once that is stable, it will be easier to add generation numbers and make graph walks aware of generation numbers one-by-one.

By loading commits from the graph instead of parsing commit buffers, we save a lot of time on long commit walks. Here are some performance results for a copy of the Linux repository where 'master' has 678,653 reachable commits and is behind 'origin/master' by 59,929 commits.

| Command                          | Before | After  | Rel % |
|----------------------------------|--------|--------|-------|
| log --oneline --topo-order -1000 |  8.31s |  0.94s | -88%  |
| branch -vv                       |  1.02s |  0.14s | -86%  |
| rev-list --all                   |  5.89s |  1.07s | -81%  |
| rev-list --all --objects         | 66.15s | 58.45s | -11%  |

To test this yourself, run the following on your repo:

  git config core.commitGraph true
  git show-ref -s | git commit-graph write --stdin-commits

The second command writes a commit graph file containing every commit reachable from your refs. Now, all git commands that walk commits will check your graph first before consulting the ODB. You can run your own performance comparisons by toggling the 'core.commitGraph' setting.

[1] https://github.com/derrickstolee/git/pull/2
A GitHub pull request containing the latest version of this patch.

Derrick Stolee (14):
csum-file: rename hashclose() to finalize_hashfile()
csum-file: refactor finalize_hashfile() method
commit-graph: add format document
graph: add commit graph design document
commit-graph: create git-commit-graph builtin
commit-graph: implement write_commit_graph()
commit-graph: implement git-commit-graph write
commit-graph: implement git commit-graph read
commit-graph: add core.commitGraph setting
commit-graph: close under reachability
commit: integrate commit graph with commit parsing
commit-graph: read only from specific pack-indexes
commit-graph: build graph from starting commits
commit-graph: implement "--append" option

 .gitignore                                    |   1 +
 Documentation/config.txt                      |   4 +
 Documentation/git-commit-graph.txt            |  94 +++
 .../technical/commit-graph-format.txt         |  97 +++
 Documentation/technical/commit-graph.txt      | 163 ++++
 Makefile                                      |   2 +
 alloc.c                                       |   1 +
 builtin.h                                     |   1 +
 builtin/commit-graph.c                        | 171 ++++
 builtin/index-pack.c                          |   2 +-
 builtin/pack-objects.c                        |   6 +-
 bulk-checkin.c                                |   4 +-
 cache.h                                       |   1 +
 command-list.txt                              |   1 +
 commit-graph.c                                | 738 ++++++++++++++++++
 commit-graph.h                                |  46 ++
 commit.c                                      |   3 +
 commit.h                                      |   3 +
 config.c                                      |   5 +
 contrib/completion/git-completion.bash        |   2 +
 csum-file.c                                   |  10 +-
 csum-file.h                                   |   9 +-
 environment.c                                 |   1 +
 fast-import.c                                 |   2 +-
 git.c                                         |   1 +
 pack-bitmap-write.c                           |   2 +-
 pack-write.c                                  |   5 +-
 packfile.c                                    |   4 +-
 packfile.h                                    |   2 +
 t/t5318-commit-graph.sh                       | 224 ++++++
 30 files changed, 1584 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/git-commit-graph.txt
 create mode 100644 Documentation/technical/commit-graph-format.txt
 create mode 100644 Documentation/technical/commit-graph.txt
 create mode 100644 builtin/commit-graph.c
 create mode 100644 commit-graph.c
 create mode 100644 commit-graph.h
 create mode 100755 t/t5318-commit-graph.sh

base-commit: 468165c1d8a442994a825f3684528361727cd8c0

Signature · 1 line
2.17.0