diff options
author | Miha <miha.ravselj@ib-caddy.si> | 2014-02-25 11:56:11 +0100 |
---|---|---|
committer | Miha <miha.ravselj@ib-caddy.si> | 2014-02-25 11:56:11 +0100 |
commit | 300f44125a5abb00f6185babc9bb828aec556015 (patch) | |
tree | a33c83a50371201aa980d1eec45f351c8ac9d261 | |
parent | cb81c3a764447ceb2cd693935bf970138ea60ccc (diff) | |
download | libgit2-300f44125a5abb00f6185babc9bb828aec556015.tar.gz |
- BUGFIX #2133 (@fourplusone) in smart_protocol.c
- added MSVC cmake definitions to disable warnings
- general.c is rewritten so it is ansi-c compatible and compiles ok on microsoft windows
- some MSVC reported warning fixes
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | examples/add.c | 2 | ||||
-rw-r--r-- | examples/blame.c | 3 | ||||
-rw-r--r-- | examples/cat-file.c | 2 | ||||
-rw-r--r-- | examples/common.c | 2 | ||||
-rw-r--r-- | examples/general.c | 82 | ||||
-rw-r--r-- | examples/network/clone.c | 2 | ||||
-rw-r--r-- | src/transports/smart_protocol.c | 4 | ||||
-rw-r--r-- | src/transports/ssh.c | 3 |
9 files changed, 57 insertions, 50 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d6b327503..27cf1a558 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,8 @@ INCLUDE(CheckLibraryExists) # Build options # -OPTION( SONAME "Set the (SO)VERSION of the target" ON ) +OPTION( SONAME + "Set the (SO)VERSION of the target" ON ) OPTION( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON ) OPTION( THREADSAFE "Build libgit2 as threadsafe" OFF ) OPTION( BUILD_CLAR "Build Tests using the Clar suite" ON ) @@ -57,6 +58,10 @@ IF(MSVC) # By default, libgit2 is built with WinHTTP. To use the built-in # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. OPTION( WINHTTP "Use Win32 WinHTTP routines" ON ) + + ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
+ ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) + ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE) ENDIF() # This variable will contain the libraries we need to put into diff --git a/examples/add.c b/examples/add.c index 336596bde..0c6076e81 100644 --- a/examples/add.c +++ b/examples/add.c @@ -78,7 +78,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo git_status_t status; (void)matched_pathspec; - if (git_status_file(&status, p.repo, path)) { + if (git_status_file((unsigned int*)(&status), p.repo, path)) { return -1; //abort } diff --git a/examples/blame.c b/examples/blame.c index 1f5db69a1..d7b843cc2 100644 --- a/examples/blame.c +++ b/examples/blame.c @@ -105,8 +105,9 @@ int main(int argc, char *argv[]) if (break_on_null_hunk && !hunk) break; if (hunk) { - break_on_null_hunk = 1; char sig[128] = {0}; + break_on_null_hunk = 1; + git_oid_tostr(oid, 10, &hunk->final_commit_id); snprintf(sig, 30, "%s <%s>", hunk->final_signature->name, hunk->final_signature->email); diff --git a/examples/cat-file.c b/examples/cat-file.c index fa6add07b..52399fa8a 100644 --- a/examples/cat-file.c +++ b/examples/cat-file.c @@ -42,7 +42,7 @@ static void print_signature(const char *header, const git_signature *sig) static void show_blob(const git_blob *blob) { /* ? Does this need crlf filtering? */ - fwrite(git_blob_rawcontent(blob), git_blob_rawsize(blob), 1, stdout); + fwrite(git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob), 1, stdout); } /** Show each entry with its type, id and attributes */ diff --git a/examples/common.c b/examples/common.c index 12dbccf59..a066c153c 100644 --- a/examples/common.c +++ b/examples/common.c @@ -156,7 +156,7 @@ int diff_output( const git_diff_line *l, void *p) { - FILE *fp = p; + FILE *fp = (FILE*)p; (void)d; (void)h; diff --git a/examples/general.c b/examples/general.c index ae8756338..235055906 100644 --- a/examples/general.c +++ b/examples/general.c @@ -71,6 +71,43 @@ int main (int argc, char** argv) int error; const char *repo_path = (argc > 1) ? argv[1] : "/opt/libgit2-test/.git"; git_repository *repo; + char* hex; + git_oid oid; + char out[41]; + git_odb* odb; + git_odb_object *obj; + git_otype otype; + const unsigned char *data; + const char *str_type; + git_commit* commit; + const git_signature *author, *cmtter; + const char *message; + time_t ctime; + unsigned int parents, p; + git_oid tree_id, parent_id, commit_id; + git_tree *tree; + git_commit *parent; + git_tag *tag; + const char *tmessage, *tname; + git_otype ttype; + const git_tree_entry *entry; + git_object *objt; + size_t cnt; + git_blob *blob; + git_revwalk *walk; + git_commit *wcommit; + const git_signature *cauth; + const char *cmsg; + git_index *index; + unsigned int i, ecount; + git_strarray ref_list; + const char *refname; + git_reference *ref; + const char *email; + int32_t j; + git_config *cfg; + char config_path[256]; + error = git_repository_open(&repo, repo_path); check_error(error, "opening repository"); @@ -80,12 +117,11 @@ int main (int argc, char** argv) // For our first example, we will convert a 40 character hex value to the // 20 byte raw SHA1 value. printf("*Hex to Raw*\n"); - char hex[] = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"; + hex = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"; // The `git_oid` is the structure that keeps the SHA value. We will use // this throughout the example for storing the value of the current SHA // key we're working with. - git_oid oid; git_oid_fromstr(&oid, hex); // Once we've converted the string into the oid value, we can get the raw @@ -94,7 +130,6 @@ int main (int argc, char** argv) // Next we will convert the 20 byte raw SHA1 value to a human readable 40 // char hex value. printf("\n*Raw to Hex*\n"); - char out[41]; out[40] = '\0'; // If you have a oid, you can easily get the hex value of the SHA as well. @@ -109,16 +144,11 @@ int main (int argc, char** argv) // repository. // // [odb]: http://libgit2.github.com/libgit2/#HEAD/group/odb - git_odb *odb; git_repository_odb(&odb, repo); // #### Raw Object Reading printf("\n*Raw Object Read*\n"); - git_odb_object *obj; - git_otype otype; - const unsigned char *data; - const char *str_type; // We can read raw objects directly from the object database if we have // the oid (SHA) of the object. This allows us to access objects without @@ -177,17 +207,11 @@ int main (int argc, char** argv) printf("\n*Commit Parsing*\n"); - git_commit *commit; git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"); error = git_commit_lookup(&commit, repo, &oid); check_error(error, "looking up commit"); - const git_signature *author, *cmtter; - const char *message; - time_t ctime; - unsigned int parents, p; - // Each of the properties of the commit object are accessible via methods, // including commonly needed variations, such as `git_commit_time` which // returns the author time and `git_commit_message` which gives you the @@ -229,9 +253,6 @@ int main (int argc, char** argv) // [cd]: http://libgit2.github.com/libgit2/#HEAD/group/commit printf("\n*Commit Writing*\n"); - git_oid tree_id, parent_id, commit_id; - git_tree *tree; - git_commit *parent; // Creating signatures for an authoring identity and time is simple. You // will need to do this to specify who created a commit and when. Default @@ -277,9 +298,6 @@ int main (int argc, char** argv) // // [tm]: http://libgit2.github.com/libgit2/#HEAD/group/tag printf("\n*Tag Parsing*\n"); - git_tag *tag; - const char *tmessage, *tname; - git_otype ttype; // We create an oid for the tag object if we know the SHA and look it up // the same way that we would a commit (or any other object). @@ -310,16 +328,13 @@ int main (int argc, char** argv) // [tp]: http://libgit2.github.com/libgit2/#HEAD/group/tree printf("\n*Tree Parsing*\n"); - const git_tree_entry *entry; - git_object *objt; - // Create the oid and lookup the tree object just like the other objects. git_oid_fromstr(&oid, "2a741c18ac5ff082a7caaec6e74db3075a1906b5"); git_tree_lookup(&tree, repo, &oid); // Getting the count of entries in the tree so you can iterate over them // if you want to. - size_t cnt = git_tree_entrycount(tree); // 3 + cnt = git_tree_entrycount(tree); // 3 printf("tree entries: %d\n", (int)cnt); entry = git_tree_entry_byindex(tree, 0); @@ -351,7 +366,6 @@ int main (int argc, char** argv) // [ba]: http://libgit2.github.com/libgit2/#HEAD/group/blob printf("\n*Blob Parsing*\n"); - git_blob *blob; git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08"); git_blob_lookup(&blob, repo, &oid); @@ -376,8 +390,6 @@ int main (int argc, char** argv) // [rw]: http://libgit2.github.com/libgit2/#HEAD/group/revwalk printf("\n*Revwalking*\n"); - git_revwalk *walk; - git_commit *wcommit; git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); @@ -393,9 +405,6 @@ int main (int argc, char** argv) git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE); git_revwalk_push(walk, &oid); - const git_signature *cauth; - const char *cmsg; - // Now that we have the starting point pushed onto the walker, we start // asking for ancestors. It will return them in the sorting order we asked // for as commit oids. We can then lookup and parse the commited pointed @@ -427,9 +436,6 @@ int main (int argc, char** argv) printf("\n*Index Walking*\n"); - git_index *index; - unsigned int i, ecount; - // You can either open the index from the standard location in an open // repository, as we're doing here, or you can open and manipulate any // index file with `git_index_open_bare()`. The index for the repository @@ -465,12 +471,8 @@ int main (int argc, char** argv) // Here we will implement something like `git for-each-ref` simply listing // out all available references and the object SHA they resolve to. - git_strarray ref_list; git_reference_list(&ref_list, repo); - const char *refname; - git_reference *ref; - // Now that we have the list of reference names, we can lookup each ref // one at a time and resolve them to the SHA, then print both values out. for (i = 0; i < ref_list.count; ++i) { @@ -503,13 +505,7 @@ int main (int argc, char** argv) printf("\n*Config Listing*\n"); - const char *email; - int32_t j; - - git_config *cfg; - // Open a config object so we can read global values from it. - char config_path[256]; sprintf(config_path, "%s/config", repo_path); check_error(git_config_open_ondisk(&cfg, config_path), "opening config"); diff --git a/examples/network/clone.c b/examples/network/clone.c index 4df47eb7f..a982c13c2 100644 --- a/examples/network/clone.c +++ b/examples/network/clone.c @@ -22,7 +22,7 @@ static void print_progress(const progress_data *pd) int index_percent = (100*pd->fetch_progress.indexed_objects) / pd->fetch_progress.total_objects; int checkout_percent = pd->total_steps > 0 ? (100 * pd->completed_steps) / pd->total_steps - : 0.f; + : 0; int kbytes = pd->fetch_progress.received_bytes / 1024; if (pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) { diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c index dd9b5e0ed..7e8fcdd92 100644 --- a/src/transports/smart_protocol.c +++ b/src/transports/smart_protocol.c @@ -579,6 +579,10 @@ int git_smart__download_pack( done: if (writepack) writepack->free(writepack); + if (progress_cb) { + t->packetsize_cb = NULL; + t->packetsize_payload = NULL; + } return error; } diff --git a/src/transports/ssh.c b/src/transports/ssh.c index 37f17080a..bece0b45d 100644 --- a/src/transports/ssh.c +++ b/src/transports/ssh.c @@ -53,6 +53,7 @@ static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg) static int gen_proto(git_buf *request, const char *cmd, const char *url) { char *repo; + int len; if (!git__prefixcmp(url, prefix_ssh)) { url = url + strlen(prefix_ssh); @@ -67,7 +68,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) return -1; } - int len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1; + len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1; git_buf_grow(request, len); git_buf_printf(request, "%s '%s'", cmd, repo); |