Skip to content

Commit d0f5c6a

Browse files
committed
add
1 parent dfe52cc commit d0f5c6a

File tree

6 files changed

+1974
-4577
lines changed

6 files changed

+1974
-4577
lines changed

emscriptenbuild/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ done
4444
# Before building, remove any ../libgit2/src/ transports/emscriptenhttp.c left from running setup.sh
4545
[ -f "../libgit2/src/libgit2/transports/emscriptenhttp-async.c" ] && rm ../libgit2/src/libgit2/transports/emscriptenhttp-async.c
4646

47-
emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS --pre-js $(pwd)/pre.js $POST_JS -s \"EXPORTED_RUNTIME_METHODS=['FS','MEMFS','IDBFS','NODEFS','callMain']\" -sFORCE_FILESYSTEM -sEXPORT_ES6 -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=131072 -lidbfs.js -lnodefs.js -flto" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ..
47+
emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS --pre-js $(pwd)/pre.js $POST_JS -s \"EXPORTED_RUNTIME_METHODS=['FS','MEMFS','IDBFS','NODEFS','callMain']\" -sFORCE_FILESYSTEM -sEXPORT_ES6 -sINVOKE_RUN=0 -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=5MB -lidbfs.js -lnodefs.js -flto" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ..
4848
emmake make lg2

libgit2patchedfiles/examples/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern int lg2_init(git_repository *repo, int argc, char **argv);
7272
extern int lg2_log(git_repository *repo, int argc, char **argv);
7373
extern int lg2_log_last_commit_of_branch(git_repository *repo, int argc, char **argv);
7474
extern int lg2_log_git_merge_base(git_repository *repo, int argc, char **argv);
75+
extern int lg2_log_git_merge_base_commits(git_repository *repo, int argc, char **argv);
7576
extern int lg2_ls_files(git_repository *repo, int argc, char **argv);
7677
extern int lg2_ls_remote(git_repository *repo, int argc, char **argv);
7778
extern int lg2_merge(git_repository *repo, int argc, char **argv);

libgit2patchedfiles/examples/lg2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct {
2828
{ "log", lg2_log, 1 },
2929
{ "log-last-commit-of-branch", lg2_log_last_commit_of_branch, 1 },
3030
{ "log-git-merge-base", lg2_log_git_merge_base, 1 },
31+
{ "log-git-merge-base-commits", lg2_log_git_merge_base_commits, 1 },
3132
{ "ls-files", lg2_ls_files, 1 },
3233
{ "ls-remote", lg2_ls_remote, 1 },
3334
{ "merge", lg2_merge, 1 },
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* libgit2 "log" example - shows how to walk history and get commit info
3+
*
4+
* Written by the libgit2 contributors
5+
*
6+
* To the extent possible under law, the author(s) have dedicated all copyright
7+
* and related and neighboring rights to this software to the public domain
8+
* worldwide. This software is distributed without any warranty.
9+
*
10+
* You should have received a copy of the CC0 Public Domain Dedication along
11+
* with this software. If not, see
12+
* <http://creativecommons.org/publicdomain/zero/1.0/>.
13+
*/
14+
15+
#include "common.h"
16+
17+
/** utility functions that parse options and help with log output */
18+
static void print_time(const git_time *intime, const char *prefix);
19+
static void print_commit_info(git_commit *commit);
20+
21+
int lg2_log_git_merge_base_commits(git_repository *repo, int argc, char *argv[])
22+
{
23+
git_oid merge_base_oid;
24+
char* commit_id_1 = NULL;
25+
char* commit_id_2 = NULL;
26+
git_commit *commit_1 = NULL;
27+
git_commit *commit_2 = NULL;
28+
git_oid oid_1;
29+
git_oid oid_2;
30+
int error;
31+
32+
if (argc != 3) {
33+
fprintf(stderr, "You have to specify exactly two commit ids. Usage: git log-git-merge-base <commitId1> <commitId2>\n");
34+
goto cleanup;
35+
} else {
36+
commit_id_1 = argv[1];
37+
commit_id_2 = argv[2];
38+
}
39+
40+
// Lookup commit_id_1 commit by hash
41+
error = git_oid_fromstr(&oid_1, commit_id_1);
42+
if (error < 0) {
43+
fprintf(stderr, "Failed to convert commitId1 commit hash.\n");
44+
goto cleanup;
45+
}
46+
47+
error = git_commit_lookup(&commit_1, repo, &oid_1);
48+
if (error < 0) {
49+
fprintf(stderr, "Failed to lookup commitId1 commit.\n");
50+
goto cleanup;
51+
}
52+
53+
// Lookup commit_id_2 commit by hash
54+
error = git_oid_fromstr(&oid_2, commit_id_2);
55+
if (error < 0) {
56+
fprintf(stderr, "Failed to convert commitId2 commit hash.\n");
57+
goto cleanup;
58+
}
59+
60+
error = git_commit_lookup(&commit_2, repo, &oid_2);
61+
if (error < 0) {
62+
fprintf(stderr, "Failed to lookup commitId2 commit.\n");
63+
goto cleanup;
64+
}
65+
66+
// Find the merge base between commitId1 and commitId2
67+
error = git_merge_base(&merge_base_oid, repo, &oid_1, &oid_2);
68+
if (error < 0) {
69+
fprintf(stderr, "Failed to find merge base.\n");
70+
goto cleanup;
71+
}
72+
73+
// Setup revwalker
74+
git_revwalk *walker;
75+
git_revwalk_new(&walker, repo);
76+
git_revwalk_sorting(walker, GIT_SORT_TIME | GIT_SORT_REVERSE);
77+
git_revwalk_push(walker, &oid_2);
78+
git_revwalk_hide(walker, &merge_base_oid);
79+
80+
// Log commit list
81+
git_oid oid;
82+
git_commit *commit;
83+
84+
while (!git_revwalk_next(&oid, walker)) {
85+
git_commit_lookup(&commit, repo, &oid);
86+
print_commit_info(commit);
87+
git_commit_free(commit);
88+
}
89+
90+
cleanup:
91+
git_commit_free(commit_1);
92+
git_commit_free(commit_2);
93+
if (walker) git_revwalk_free(walker);
94+
95+
return 0;
96+
}

0 commit comments

Comments
 (0)