10000 Add example program to emulate 'git log' and create pathspec matching API by arrbee · Pull Request #1711 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Add example program to emulate 'git log' and create pathspec matching API #1711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extending log example code
This adds more command line processing to the example version of
log.  In particular, this adds the funky command line processing
that allows an arbitrary series of revisions followed by an
arbitrary number of paths and/or glob patterns.

The actual logging part still isn't implemented.
  • Loading branch information
arrbee committed Jul 3, 2013
commit 90d4f6e8b30d7d6695c6fa569d879dc215b5163d
53 changes: 50 additions & 3 deletions examples/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,71 @@ static void usage(const char *message, const char *arg)

int main(int argc, char *argv[])
{
int i;
int i, j, last_nonoption, force_files = -1;
char *a;
const char *dir = ".";
git_repository *repo;
git_revwalk *walker;
git_revspec revs;

git_threads_init();

for (i = 1; i < argc; ++i) {
for (i = 1, last_nonoption = 1; i < argc; ++i) {
a = argv[i];

if (a[0] != '-') {
if (a[0] != '-' || force_files > 0) {
/* condense args not prefixed with '-' to start of argv */
if (last_nonoption != i)
argv[last_nonoption] = a;
last_nonoption++;
}
else if (!strcmp(a, "--"))
force_files = last_nonoption; /* copy all args as filenames */
else if (!check_str_param(a, "--git-dir=", &dir))
usage("Unknown argument", a);
}

check(git_repository_open_ext(&repo, dir, 0, NULL),
"Could not open repository");
check(git_revwalk_new(&walker, repo),
"Could not create revision walker");

if (force_files < 0)
force_files = last_nonoption;

for (i = 1; i < force_files; ) {
printf("option '%s'\n", argv[i]);

if (!git_revparse(&revs, repo, argv[i])) {
char str[GIT_OID_HEXSZ+1];

if (revs.from) {
git_oid_tostr(str, sizeof(str), git_object_id(revs.from));
printf("revwalk from %s\n", str);
}
if (revs.to) {
git_oid_tostr(str, sizeof(str), git_object_id(revs.to));
printf("revwalk to %s\n", str);
}

/* push / hide / merge-base in revwalker */

++i;
} else {
/* shift array down */
for (a = argv[i], j = i + 1; j < force_files; ++j)
argv[j - 1] = argv[j];
argv[--force_files] = a;
}
}

if (i == 1) {
/* no revs pushed so push HEAD */
printf("revwalk HEAD\n");
}

for (i = force_files; i < last_nonoption; ++i)
printf("file %s\n", argv[i]);

git_repository_free(repo);
git_threads_shutdown();
Expand Down
0