summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--examples/README.md4
-rw-r--r--examples/args.h2
-rw-r--r--examples/blame.c4
-rw-r--r--examples/checkout.c6
-rw-r--r--examples/for-each-ref.c2
-rw-r--r--examples/general.c26
-rw-r--r--examples/log.c56
-rw-r--r--examples/merge.c4
-rw-r--r--examples/push.c5
9 files changed, 67 insertions, 42 deletions
diff --git a/examples/README.md b/examples/README.md
index 769c4b2..0f1f253 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -15,8 +15,8 @@ so there are no restrictions on their use.
For annotated HTML versions, see the "Examples" section of:
- http://libgit2.github.com/libgit2
+ https://libgit2.org/libgit2
such as:
- http://libgit2.github.com/libgit2/ex/HEAD/general.html
+ https://libgit2.org/libgit2/ex/HEAD/general.html
diff --git a/examples/args.h b/examples/args.h
index d626f98..4db0493 100644
--- a/examples/args.h
+++ b/examples/args.h
@@ -8,7 +8,7 @@ struct args_info {
int argc;
char **argv;
int pos;
- int opts_done : 1; /**< Did we see a -- separator */
+ unsigned int opts_done : 1; /**< Did we see a -- separator */
};
#define ARGS_INFO_INIT { argc, argv, 0, 0 }
#define ARGS_CURRENT(args) args->argv[args->pos]
diff --git a/examples/blame.c b/examples/blame.c
index 77087a5..0996e7a 100644
--- a/examples/blame.c
+++ b/examples/blame.c
@@ -47,6 +47,10 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
if (o.M) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
if (o.C) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES;
if (o.F) blameopts.flags |= GIT_BLAME_FIRST_PARENT;
+ if (o.start_line && o.end_line) {
+ blameopts.min_line = o.start_line;
+ blameopts.max_line = o.end_line;
+ }
/**
* The commit range comes in "committish" form. Use the rev-parse API to
diff --git a/examples/checkout.c b/examples/checkout.c
index ac7b742..82567cd 100644
--- a/examples/checkout.c
+++ b/examples/checkout.c
@@ -35,9 +35,9 @@
*/
typedef struct {
- int force : 1;
- int progress : 1;
- int perf : 1;
+ unsigned int force : 1;
+ unsigned int progress : 1;
+ unsigned int perf : 1;
} checkout_options;
static void print_usage(void)
diff --git a/examples/for-each-ref.c b/examples/for-each-ref.c
index a070674..f745bc3 100644
--- a/examples/for-each-ref.c
+++ b/examples/for-each-ref.c
@@ -25,6 +25,8 @@ static int show_ref(git_reference *ref, void *data)
git_object_type2string(git_object_type(obj)),
git_reference_name(ref));
+ git_object_free(obj);
+ git_reference_free(ref);
if (resolved)
git_reference_free(resolved);
return 0;
diff --git a/examples/general.c b/examples/general.c
index 7f44cd7..0275f84 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -31,8 +31,8 @@
* Git Internals that you will need to know to work with Git at this level,
* check out [Chapter 10][pg] of the Pro Git book.
*
- * [lg]: http://libgit2.github.com
- * [ap]: http://libgit2.github.com/libgit2
+ * [lg]: https://libgit2.org
+ * [ap]: https://libgit2.org/libgit2
* [pg]: https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain
*/
@@ -97,7 +97,7 @@ int lg2_general(git_repository *repo, int argc, char** argv)
*
* (Try running this program against tests/resources/testrepo.git.)
*
- * [me]: http://libgit2.github.com/libgit2/#HEAD/group/repository
+ * [me]: https://libgit2.org/libgit2/#HEAD/group/repository
*/
repo_path = (argc > 1) ? argv[1] : "/opt/libgit2-test/.git";
@@ -173,7 +173,7 @@ static void oid_parsing(git_oid *oid)
* working with raw objects, we'll need to get this structure from the
* repository.
*
- * [odb]: http://libgit2.github.com/libgit2/#HEAD/group/odb
+ * [odb]: https://libgit2.org/libgit2/#HEAD/group/odb
*/
static void object_database(git_repository *repo, git_oid *oid)
{
@@ -262,7 +262,7 @@ static void object_database(git_repository *repo, git_oid *oid)
* of them here. You can read about the other ones in the [commit API
* docs][cd].
*
- * [cd]: http://libgit2.github.com/libgit2/#HEAD/group/commit
+ * [cd]: https://libgit2.org/libgit2/#HEAD/group/commit
*/
static void commit_writing(git_repository *repo)
{
@@ -347,7 +347,7 @@ static void commit_writing(git_repository *repo)
* data in the commit - the author (name, email, datetime), committer
* (same), tree, message, encoding and parent(s).
*
- * [pco]: http://libgit2.github.com/libgit2/#HEAD/group/commit
+ * [pco]: https://libgit2.org/libgit2/#HEAD/group/commit
*/
static void commit_parsing(git_repository *repo)
{
@@ -418,7 +418,7 @@ static void commit_parsing(git_repository *repo)
* functions very similarly to the commit lookup, parsing and creation
* methods, since the objects themselves are very similar.
*
- * [tm]: http://libgit2.github.com/libgit2/#HEAD/group/tag
+ * [tm]: https://libgit2.org/libgit2/#HEAD/group/tag
*/
static void tag_parsing(git_repository *repo)
{
@@ -472,7 +472,7 @@ static void tag_parsing(git_repository *repo)
* object type in Git, but a useful structure for parsing and traversing
* tree entries.
*
- * [tp]: http://libgit2.github.com/libgit2/#HEAD/group/tree
+ * [tp]: https://libgit2.org/libgit2/#HEAD/group/tree
*/
static void tree_parsing(git_repository *repo)
{
@@ -536,7 +536,7 @@ static void tree_parsing(git_repository *repo)
* from disk and writing it to the db and getting the oid back so you
* don't have to do all those steps yourself.
*
- * [ba]: http://libgit2.github.com/libgit2/#HEAD/group/blob
+ * [ba]: https://libgit2.org/libgit2/#HEAD/group/blob
*/
static void blob_parsing(git_repository *repo)
{
@@ -578,7 +578,7 @@ static void blob_parsing(git_repository *repo)
* that were ancestors of (reachable from) a given starting point. This
* can allow you to create `git log` type functionality.
*
- * [rw]: http://libgit2.github.com/libgit2/#HEAD/group/revwalk
+ * [rw]: https://libgit2.org/libgit2/#HEAD/group/revwalk
*/
static void revwalking(git_repository *repo)
{
@@ -643,7 +643,7 @@ static void revwalking(git_repository *repo)
* The [index file API][gi] allows you to read, traverse, update and write
* the Git index file (sometimes thought of as the staging area).
*
- * [gi]: http://libgit2.github.com/libgit2/#HEAD/group/index
+ * [gi]: https://libgit2.org/libgit2/#HEAD/group/index
*/
static void index_walking(git_repository *repo)
{
@@ -687,7 +687,7 @@ static void index_walking(git_repository *repo)
* references such as branches, tags and remote references (everything in
* the .git/refs directory).
*
- * [ref]: http://libgit2.github.com/libgit2/#HEAD/group/reference
+ * [ref]: https://libgit2.org/libgit2/#HEAD/group/reference
*/
static void reference_listing(git_repository *repo)
{
@@ -740,7 +740,7 @@ static void reference_listing(git_repository *repo)
* The [config API][config] allows you to list and update config values
* in any of the accessible config file locations (system, global, local).
*
- * [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
+ * [config]: https://libgit2.org/libgit2/#HEAD/group/config
*/
static void config_files(const char *repo_path, git_repository* repo)
{
diff --git a/examples/log.c b/examples/log.c
index 4b0a95d..62a6eb5 100644
--- a/examples/log.c
+++ b/examples/log.c
@@ -50,6 +50,7 @@ static int add_revision(struct log_state *s, const char *revstr);
/** log_options holds other command line options that affect log output */
struct log_options {
int show_diff;
+ int show_oneline;
int show_log_size;
int skip, limit;
int min_parents, max_parents;
@@ -81,9 +82,11 @@ int lg2_log(git_repository *repo, int argc, char *argv[])
git_commit *commit = NULL;
git_pathspec *ps = NULL;
+ memset(&s, 0, sizeof(s));
+
/** Parse arguments and set up revwalker. */
- last_arg = parse_options(&s, &opt, argc, argv);
s.repo = repo;
+ last_arg = parse_options(&s, &opt, argc, argv);
diffopts.pathspec.strings = &argv[last_arg];
diffopts.pathspec.count = argc - last_arg;
@@ -335,34 +338,45 @@ static void print_commit(git_commit *commit, struct log_options *opts)
const char *scan, *eol;
git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
- printf("commit %s\n", buf);
- if (opts->show_log_size) {
- printf("log size %d\n", (int)strlen(git_commit_message(commit)));
- }
+ if (opts->show_oneline) {
+ printf("%s ", buf);
+ } else {
+ printf("commit %s\n", buf);
- if ((count = (int)git_commit_parentcount(commit)) > 1) {
- printf("Merge:");
- for (i = 0; i < count; ++i) {
- git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
- printf(" %s", buf);
+ if (opts->show_log_size) {
+ printf("log size %d\n", (int)strlen(git_commit_message(commit)));
+ }
+
+ if ((count = (int)git_commit_parentcount(commit)) > 1) {
+ printf("Merge:");
+ for (i = 0; i < count; ++i) {
+ git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
+ printf(" %s", buf);
+ }
+ printf("\n");
}
- printf("\n");
- }
- if ((sig = git_commit_author(commit)) != NULL) {
- printf("Author: %s <%s>\n", sig->name, sig->email);
- print_time(&sig->when, "Date: ");
+ if ((sig = git_commit_author(commit)) != NULL) {
+ printf("Author: %s <%s>\n", sig->name, sig->email);
+ print_time(&sig->when, "Date: ");
+ }
+ printf("\n");
}
- printf("\n");
for (scan = git_commit_message(commit); scan && *scan; ) {
for (eol = scan; *eol && *eol != '\n'; ++eol) /* find eol */;
- printf(" %.*s\n", (int)(eol - scan), scan);
+ if (opts->show_oneline)
+ printf("%.*s\n", (int)(eol - scan), scan);
+ else
+ printf(" %.*s\n", (int)(eol - scan), scan);
scan = *eol ? eol + 1 : NULL;
+ if (opts->show_oneline)
+ break;
}
- printf("\n");
+ if (!opts->show_oneline)
+ printf("\n");
}
/** Helper to find how many files in a commit changed from its nth parent. */
@@ -407,8 +421,6 @@ static int parse_options(
struct log_state *s, struct log_options *opt, int argc, char **argv)
{
struct args_info args = ARGS_INFO_INIT;
-
- memset(s, 0, sizeof(*s));
s->sorting = GIT_SORT_TIME;
memset(opt, 0, sizeof(*opt));
@@ -424,7 +436,7 @@ static int parse_options(
else
/** Try failed revision parse as filename. */
break;
- } else if (!match_arg_separator(&args)) {
+ } else if (match_arg_separator(&args)) {
break;
}
else if (!strcmp(a, "--date-order"))
@@ -474,6 +486,8 @@ static int parse_options(
opt->show_diff = 1;
else if (!strcmp(a, "--log-size"))
opt->show_log_size = 1;
+ else if (!strcmp(a, "--oneline"))
+ opt->show_oneline = 1;
else
usage("Unsupported argument", a);
}
diff --git a/examples/merge.c b/examples/merge.c
index 460c06a..718c767 100644
--- a/examples/merge.c
+++ b/examples/merge.c
@@ -30,7 +30,7 @@ struct merge_options {
git_annotated_commit **annotated;
size_t annotated_count;
- int no_commit : 1;
+ unsigned int no_commit : 1;
};
static void print_usage(void)
@@ -263,7 +263,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, struct me
sign, sign,
NULL, msg,
tree,
- opts->annotated_count + 1, (const git_commit **)parents);
+ opts->annotated_count + 1, parents);
check_lg2(err, "failed to create commit", NULL);
/* We're done merging, cleanup the repository state */
diff --git a/examples/push.c b/examples/push.c
index bcf3076..5113eed 100644
--- a/examples/push.c
+++ b/examples/push.c
@@ -32,6 +32,7 @@
/** Entry point for this command */
int lg2_push(git_repository *repo, int argc, char **argv) {
git_push_options options;
+ git_remote_callbacks callbacks;
git_remote* remote = NULL;
char *refspec = "refs/heads/master";
const git_strarray refspecs = {
@@ -47,7 +48,11 @@ int lg2_push(git_repository *repo, int argc, char **argv) {
check_lg2(git_remote_lookup(&remote, repo, "origin" ), "Unable to lookup remote", NULL);
+ check_lg2(git_remote_init_callbacks(&callbacks, GIT_REMOTE_CALLBACKS_VERSION), "Error initializing remote callbacks", NULL);
+ callbacks.credentials = cred_acquire_cb;
+
check_lg2(git_push_options_init(&options, GIT_PUSH_OPTIONS_VERSION ), "Error initializing push", NULL);
+ options.callbacks = callbacks;
check_lg2(git_remote_push(remote, &refspecs, &options), "Error pushing", NULL);