rugged 0.17.0.b6 → 0.17.0.b7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README.md +3 -3
  2. data/Rakefile +3 -1
  3. data/ext/rugged/rugged.c +30 -0
  4. data/ext/rugged/rugged.h +9 -0
  5. data/ext/rugged/rugged_branch.c +306 -0
  6. data/ext/rugged/rugged_config.c +16 -13
  7. data/ext/rugged/rugged_index.c +25 -0
  8. data/ext/rugged/rugged_object.c +6 -2
  9. data/ext/rugged/rugged_reference.c +11 -18
  10. data/ext/rugged/rugged_revwalk.c +1 -1
  11. data/lib/rugged.rb +1 -0
  12. data/lib/rugged/branch.rb +28 -0
  13. data/lib/rugged/commit.rb +5 -5
  14. data/lib/rugged/repository.rb +32 -7
  15. data/lib/rugged/tag.rb +5 -1
  16. data/lib/rugged/version.rb +1 -1
  17. data/test/branch_test.rb +227 -0
  18. data/test/config_test.rb +1 -1
  19. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  20. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  21. data/test/index_test.rb +31 -0
  22. data/test/index_test.rb~ +218 -0
  23. data/test/lib_test.rb +22 -0
  24. data/test/reference_test.rb +5 -3
  25. data/vendor/libgit2/Makefile.embed +1 -1
  26. data/vendor/libgit2/include/git2.h +1 -0
  27. data/vendor/libgit2/include/git2/branch.h +17 -13
  28. data/vendor/libgit2/include/git2/checkout.h +83 -22
  29. data/vendor/libgit2/include/git2/clone.h +6 -3
  30. data/vendor/libgit2/include/git2/common.h +1 -8
  31. data/vendor/libgit2/include/git2/config.h +185 -26
  32. data/vendor/libgit2/include/git2/diff.h +229 -17
  33. data/vendor/libgit2/include/git2/errors.h +39 -1
  34. data/vendor/libgit2/include/git2/ignore.h +6 -3
  35. data/vendor/libgit2/include/git2/indexer.h +1 -0
  36. data/vendor/libgit2/include/git2/merge.h +1 -1
  37. data/vendor/libgit2/include/git2/object.h +7 -4
  38. data/vendor/libgit2/include/git2/odb.h +4 -2
  39. data/vendor/libgit2/include/git2/odb_backend.h +6 -0
  40. data/vendor/libgit2/include/git2/oid.h +2 -0
  41. data/vendor/libgit2/include/git2/pack.h +89 -0
  42. data/vendor/libgit2/include/git2/refs.h +88 -0
  43. data/vendor/libgit2/include/git2/refspec.h +0 -8
  44. data/vendor/libgit2/include/git2/remote.h +34 -1
  45. data/vendor/libgit2/include/git2/repository.h +238 -6
  46. data/vendor/libgit2/include/git2/reset.h +4 -1
  47. data/vendor/libgit2/include/git2/revwalk.h +1 -1
  48. data/vendor/libgit2/include/git2/status.h +19 -14
  49. data/vendor/libgit2/include/git2/strarray.h +54 -0
  50. data/vendor/libgit2/include/git2/submodule.h +451 -45
  51. data/vendor/libgit2/include/git2/tag.h +16 -0
  52. data/vendor/libgit2/include/git2/tree.h +2 -2
  53. data/vendor/libgit2/include/git2/types.h +4 -0
  54. data/vendor/libgit2/src/amiga/map.c +4 -7
  55. data/vendor/libgit2/src/attr.c +21 -13
  56. data/vendor/libgit2/src/attr.h +3 -1
  57. data/vendor/libgit2/src/attr_file.c +14 -14
  58. data/vendor/libgit2/src/attr_file.h +6 -5
  59. data/vendor/libgit2/src/blob.c +22 -12
  60. data/vendor/libgit2/src/branch.c +62 -66
  61. data/vendor/libgit2/src/buffer.c +63 -14
  62. data/vendor/libgit2/src/buffer.h +4 -0
  63. data/vendor/libgit2/src/cache.c +5 -4
  64. data/vendor/libgit2/src/checkout.c +381 -159
  65. data/vendor/libgit2/src/clone.c +221 -94
  66. data/vendor/libgit2/src/common.h +13 -3
  67. data/vendor/libgit2/src/compress.c +53 -0
  68. data/vendor/libgit2/src/compress.h +16 -0
  69. data/vendor/libgit2/src/config.c +380 -175
  70. data/vendor/libgit2/src/config.h +2 -5
  71. data/vendor/libgit2/src/config_file.c +63 -46
  72. data/vendor/libgit2/src/config_file.h +16 -4
  73. data/vendor/libgit2/src/crlf.c +4 -3
  74. data/vendor/libgit2/src/delta.c +491 -0
  75. data/vendor/libgit2/src/delta.h +112 -0
  76. data/vendor/libgit2/src/diff.c +310 -67
  77. data/vendor/libgit2/src/diff.h +10 -1
  78. data/vendor/libgit2/src/diff_output.c +1030 -337
  79. data/vendor/libgit2/src/diff_output.h +86 -0
  80. data/vendor/libgit2/src/errors.c +10 -1
  81. data/vendor/libgit2/src/fetch.c +108 -24
  82. data/vendor/libgit2/src/filebuf.c +8 -2
  83. data/vendor/libgit2/src/fileops.c +342 -177
  84. data/vendor/libgit2/src/fileops.h +84 -7
  85. data/vendor/libgit2/src/filter.c +0 -35
  86. data/vendor/libgit2/src/filter.h +0 -12
  87. data/vendor/libgit2/src/{compat/fnmatch.c → fnmatch.c} +16 -4
  88. data/vendor/libgit2/src/{compat/fnmatch.h → fnmatch.h} +4 -3
  89. data/vendor/libgit2/src/global.c +4 -0
  90. data/vendor/libgit2/src/ignore.c +122 -23
  91. data/vendor/libgit2/src/ignore.h +1 -0
  92. data/vendor/libgit2/src/index.c +56 -10
  93. data/vendor/libgit2/src/index.h +2 -0
  94. data/vendor/libgit2/src/indexer.c +8 -9
  95. data/vendor/libgit2/src/iterator.c +244 -31
  96. data/vendor/libgit2/src/iterator.h +30 -1
  97. data/vendor/libgit2/src/message.c +1 -1
  98. data/vendor/libgit2/src/netops.c +44 -4
  99. data/vendor/libgit2/src/object.c +80 -69
  100. data/vendor/libgit2/src/object.h +39 -0
  101. data/vendor/libgit2/src/odb.c +79 -15
  102. data/vendor/libgit2/src/odb.h +20 -5
  103. data/vendor/libgit2/src/odb_pack.c +65 -33
  104. data/vendor/libgit2/src/oid.c +0 -3
  105. data/vendor/libgit2/src/pack-objects.c +1315 -0
  106. data/vendor/libgit2/src/pack-objects.h +87 -0
  107. data/vendor/libgit2/src/pack.c +36 -12
  108. data/vendor/libgit2/src/pack.h +1 -0
  109. data/vendor/libgit2/src/path.c +42 -9
  110. data/vendor/libgit2/src/path.h +14 -0
  111. data/vendor/libgit2/src/pkt.c +52 -2
  112. data/vendor/libgit2/src/pkt.h +10 -0
  113. data/vendor/libgit2/src/pool.h +11 -0
  114. data/vendor/libgit2/src/posix.h +8 -0
  115. data/vendor/libgit2/src/protocol.c +24 -2
  116. data/vendor/libgit2/src/protocol.h +4 -0
  117. data/vendor/libgit2/src/reflog.c +1 -1
  118. data/vendor/libgit2/src/refs.c +292 -124
  119. data/vendor/libgit2/src/refs.h +4 -2
  120. data/vendor/libgit2/src/refspec.c +117 -19
  121. data/vendor/libgit2/src/refspec.h +19 -0
  122. data/vendor/libgit2/src/remote.c +152 -48
  123. data/vendor/libgit2/src/remote.h +4 -1
  124. data/vendor/libgit2/src/repo_template.h +58 -0
  125. data/vendor/libgit2/src/repository.c +594 -179
  126. data/vendor/libgit2/src/repository.h +23 -22
  127. data/vendor/libgit2/src/reset.c +71 -29
  128. data/vendor/libgit2/src/revparse.c +26 -17
  129. data/vendor/libgit2/src/revwalk.c +36 -19
  130. data/vendor/libgit2/src/sha1.h +7 -0
  131. data/vendor/libgit2/src/{sha1.c → sha1/sha1.c} +0 -0
  132. data/vendor/libgit2/src/signature.c +12 -10
  133. data/vendor/libgit2/src/status.c +52 -6
  134. data/vendor/libgit2/src/submodule.c +1363 -255
  135. data/vendor/libgit2/src/submodule.h +102 -0
  136. data/vendor/libgit2/src/tag.c +42 -26
  137. data/vendor/libgit2/src/thread-utils.h +7 -7
  138. data/vendor/libgit2/src/transport.h +15 -1
  139. data/vendor/libgit2/src/transports/git.c +1 -1
  140. data/vendor/libgit2/src/transports/http.c +197 -36
  141. data/vendor/libgit2/src/tree.c +3 -3
  142. data/vendor/libgit2/src/unix/map.c +2 -0
  143. data/vendor/libgit2/src/unix/posix.h +1 -8
  144. data/vendor/libgit2/src/util.c +6 -1
  145. data/vendor/libgit2/src/util.h +7 -0
  146. data/vendor/libgit2/src/vector.c +16 -0
  147. data/vendor/libgit2/src/vector.h +1 -0
  148. data/vendor/libgit2/src/win32/dir.c +8 -21
  149. data/vendor/libgit2/src/win32/findfile.c +149 -0
  150. data/vendor/libgit2/src/win32/findfile.h +23 -0
  151. data/vendor/libgit2/src/win32/posix.h +3 -7
  152. data/vendor/libgit2/src/win32/posix_w32.c +44 -102
  153. data/vendor/libgit2/src/win32/pthread.c +68 -0
  154. data/vendor/libgit2/src/win32/pthread.h +7 -0
  155. data/vendor/libgit2/src/win32/utf-conv.c +60 -71
  156. data/vendor/libgit2/src/win32/utf-conv.h +4 -3
  157. metadata +70 -71
  158. data/vendor/libgit2/include/git2/windows.h +0 -59
@@ -7,10 +7,6 @@
7
7
 
8
8
  #include <assert.h>
9
9
 
10
- #ifndef GIT_WIN32
11
- #include <dirent.h>
12
- #endif
13
-
14
10
  #include "git2/clone.h"
15
11
  #include "git2/remote.h"
16
12
  #include "git2/revparse.h"
@@ -22,118 +18,226 @@
22
18
 
23
19
  #include "common.h"
24
20
  #include "remote.h"
21
+ #include "pkt.h"
25
22
  #include "fileops.h"
26
23
  #include "refs.h"
27
24
  #include "path.h"
28
25
 
29
- GIT_BEGIN_DECL
30
-
31
- struct HeadInfo {
32
- git_repository *repo;
33
- git_oid remote_head_oid;
34
- git_buf branchname;
35
- };
36
-
37
- static int create_tracking_branch(git_repository *repo, const git_oid *target, const char *name)
26
+ static int create_branch(
27
+ git_reference **branch,
28
+ git_repository *repo,
29
+ const git_oid *target,
30
+ const char *name)
38
31
  {
39
32
  git_object *head_obj = NULL;
40
33
  git_reference *branch_ref;
41
- int retcode = GIT_ERROR;
34
+ int error;
42
35
 
43
36
  /* Find the target commit */
44
- if (git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY) < 0)
45
- return GIT_ERROR;
37
+ if ((error = git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY)) < 0)
38
+ return error;
46
39
 
47
40
  /* Create the new branch */
48
- if (!git_branch_create(&branch_ref, repo, name, head_obj, 0)) {
49
- git_config *cfg;
41
+ error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
50
42
 
43
+ git_object_free(head_obj);
44
+
45
+ if (!error)
46
+ *branch = branch_ref;
47
+ else
51
48
  git_reference_free(branch_ref);
52
- /* Set up tracking */
53
- if (!git_repository_config(&cfg, repo)) {
54
- git_buf remote = GIT_BUF_INIT;
55
- git_buf merge = GIT_BUF_INIT;
56
- git_buf merge_target = GIT_BUF_INIT;
57
- if (!git_buf_printf(&remote, "branch.%s.remote", name) &&
58
- !git_buf_printf(&merge, "branch.%s.merge", name) &&
59
- !git_buf_printf(&merge_target, "refs/heads/%s", name) &&
60
- !git_config_set_string(cfg, git_buf_cstr(&remote), "origin") &&
61
- !git_config_set_string(cfg, git_buf_cstr(&merge), git_buf_cstr(&merge_target))) {
62
- retcode = 0;
63
- }
64
- git_buf_free(&remote);
65
- git_buf_free(&merge);
66
- git_buf_free(&merge_target);
67
- git_config_free(cfg);
68
- }
69
- }
70
49
 
71
- git_object_free(head_obj);
72
- return retcode;
50
+ return error;
73
51
  }
74
52
 
75
- static int reference_matches_remote_head(const char *head_name, void *payload)
53
+ static int setup_tracking_config(
54
+ git_repository *repo,
55
+ const char *branch_name,
56
+ const char *remote_name,
57
+ const char *merge_target)
58
+ {
59
+ git_config *cfg;
60
+ git_buf remote_key = GIT_BUF_INIT, merge_key = GIT_BUF_INIT;
61
+ int error = -1;
62
+
63
+ if (git_repository_config__weakptr(&cfg, repo) < 0)
64
+ return -1;
65
+
66
+ if (git_buf_printf(&remote_key, "branch.%s.remote", branch_name) < 0)
67
+ goto cleanup;
68
+
69
+ if (git_buf_printf(&merge_key, "branch.%s.merge", branch_name) < 0)
70
+ goto cleanup;
71
+
72
+ if (git_config_set_string(cfg, git_buf_cstr(&remote_key), remote_name) < 0)
73
+ goto cleanup;
74
+
75
+ if (git_config_set_string(cfg, git_buf_cstr(&merge_key), merge_target) < 0)
76
+ goto cleanup;
77
+
78
+ error = 0;
79
+
80
+ cleanup:
81
+ git_buf_free(&remote_key);
82
+ git_buf_free(&merge_key);
83
+ return error;
84
+ }
85
+
86
+ static int create_tracking_branch(
87
+ git_reference **branch,
88
+ git_repository *repo,
89
+ const git_oid *target,
90
+ const char *branch_name)
91
+ {
92
+ int error;
93
+
94
+ if ((error = create_branch(branch, repo, target, branch_name)) < 0)
95
+ return error;
96
+
97
+ return setup_tracking_config(
98
+ repo,
99
+ branch_name,
100
+ GIT_REMOTE_ORIGIN,
101
+ git_reference_name(*branch));
102
+ }
103
+
104
+ struct head_info {
105
+ git_repository *repo;
106
+ git_oid remote_head_oid;
107
+ git_buf branchname;
108
+ const git_refspec *refspec;
109
+ };
110
+
111
+ static int reference_matches_remote_head(
112
+ const char *reference_name,
113
+ void *payload)
76
114
  {
77
- struct HeadInfo *head_info = (struct HeadInfo *)payload;
115
+ struct head_info *head_info = (struct head_info *)payload;
78
116
  git_oid oid;
79
117
 
118
+ /* TODO: Should we guard against references
119
+ * which name doesn't start with refs/heads/ ?
120
+ */
121
+
80
122
  /* Stop looking if we've already found a match */
81
- if (git_buf_len(&head_info->branchname) > 0) return 0;
123
+ if (git_buf_len(&head_info->branchname) > 0)
124
+ return 0;
125
+
126
+ if (git_reference_name_to_oid(
127
+ &oid,
128
+ head_info->repo,
129
+ reference_name) < 0) {
130
+ /* TODO: How to handle not found references?
131
+ */
132
+ return -1;
133
+ }
82
134
 
83
- if (!git_reference_name_to_oid(&oid, head_info->repo, head_name) &&
84
- !git_oid_cmp(&head_info->remote_head_oid, &oid)) {
85
- git_buf_puts(&head_info->branchname,
86
- head_name+strlen("refs/remotes/origin/"));
135
+ if (git_oid_cmp(&head_info->remote_head_oid, &oid) == 0) {
136
+ /* Determine the local reference name from the remote tracking one */
137
+ if (git_refspec_transform_l(
138
+ &head_info->branchname,
139
+ head_info->refspec,
140
+ reference_name) < 0)
141
+ return -1;
142
+
143
+ if (git_buf_sets(
144
+ &head_info->branchname,
145
+ git_buf_cstr(&head_info->branchname) + strlen(GIT_REFS_HEADS_DIR)) < 0)
146
+ return -1;
87
147
  }
148
+
88
149
  return 0;
89
150
  }
90
151
 
91
- static int update_head_to_new_branch(git_repository *repo, const git_oid *target, const char *name)
152
+ static int update_head_to_new_branch(
153
+ git_repository *repo,
154
+ const git_oid *target,
155
+ const char *name)
92
156
  {
93
- int retcode = GIT_ERROR;
157
+ git_reference *tracking_branch = NULL;
158
+ int error;
94
159
 
95
- if (!create_tracking_branch(repo, target, name)) {
96
- git_reference *head;
97
- if (!git_reference_lookup(&head, repo, GIT_HEAD_FILE)) {
98
- git_buf targetbuf = GIT_BUF_INIT;
99
- if (!git_buf_printf(&targetbuf, "refs/heads/%s", name)) {
100
- retcode = git_reference_set_target(head, git_buf_cstr(&targetbuf));
101
- }
102
- git_buf_free(&targetbuf);
103
- git_reference_free(head);
104
- }
105
- }
160
+ if ((error = create_tracking_branch(
161
+ &tracking_branch,
162
+ repo,
163
+ target,
164
+ name)) < 0)
165
+ return error;
106
166
 
107
- return retcode;
167
+ error = git_repository_set_head(repo, git_reference_name(tracking_branch));
168
+
169
+ git_reference_free(tracking_branch);
170
+
171
+ return error;
108
172
  }
109
173
 
110
174
  static int update_head_to_remote(git_repository *repo, git_remote *remote)
111
175
  {
112
- int retcode = GIT_ERROR;
176
+ int retcode = -1;
113
177
  git_remote_head *remote_head;
114
- git_oid oid;
115
- struct HeadInfo head_info;
178
+ git_pkt_ref *pkt;
179
+ struct head_info head_info;
180
+ git_buf remote_master_name = GIT_BUF_INIT;
181
+
182
+ /* Did we just clone an empty repository? */
183
+ if (remote->refs.length == 0) {
184
+ return setup_tracking_config(
185
+ repo,
186
+ "master",
187
+ GIT_REMOTE_ORIGIN,
188
+ GIT_REFS_HEADS_MASTER_FILE);
189
+ }
116
190
 
117
191
  /* Get the remote's HEAD. This is always the first ref in remote->refs. */
118
- remote_head = remote->refs.contents[0];
192
+ pkt = remote->transport->refs.contents[0];
193
+ remote_head = &pkt->head;
119
194
  git_oid_cpy(&head_info.remote_head_oid, &remote_head->oid);
120
195
  git_buf_init(&head_info.branchname, 16);
121
196
  head_info.repo = repo;
122
-
123
- /* Check to see if "master" matches the remote head */
124
- if (!git_reference_name_to_oid(&oid, repo, "refs/remotes/origin/master") &&
125
- !git_oid_cmp(&remote_head->oid, &oid)) {
126
- retcode = update_head_to_new_branch(repo, &oid, "master");
197
+ head_info.refspec = git_remote_fetchspec(remote);
198
+
199
+ /* Determine the remote tracking reference name from the local master */
200
+ if (git_refspec_transform_r(
201
+ &remote_master_name,
202
+ head_info.refspec,
203
+ GIT_REFS_HEADS_MASTER_FILE) < 0)
204
+ return -1;
205
+
206
+ /* Check to see if the remote HEAD points to the remote master */
207
+ if (reference_matches_remote_head(git_buf_cstr(&remote_master_name), &head_info) < 0)
208
+ goto cleanup;
209
+
210
+ if (git_buf_len(&head_info.branchname) > 0) {
211
+ retcode = update_head_to_new_branch(
212
+ repo,
213
+ &head_info.remote_head_oid,
214
+ git_buf_cstr(&head_info.branchname));
215
+
216
+ goto cleanup;
127
217
  }
218
+
128
219
  /* Not master. Check all the other refs. */
129
- else if (!git_reference_foreach(repo, GIT_REF_LISTALL,
130
- reference_matches_remote_head,
131
- &head_info) &&
132
- git_buf_len(&head_info.branchname) > 0) {
133
- retcode = update_head_to_new_branch(repo, &head_info.remote_head_oid,
134
- git_buf_cstr(&head_info.branchname));
220
+ if (git_reference_foreach(
221
+ repo,
222
+ GIT_REF_LISTALL,
223
+ reference_matches_remote_head,
224
+ &head_info) < 0)
225
+ goto cleanup;
226
+
227
+ if (git_buf_len(&head_info.branchname) > 0) {
228
+ retcode = update_head_to_new_branch(
229
+ repo,
230
+ &head_info.remote_head_oid,
231
+ git_buf_cstr(&head_info.branchname));
232
+
233
+ goto cleanup;
234
+ } else {
235
+ /* TODO: What should we do if nothing has been found?
236
+ */
135
237
  }
136
238
 
239
+ cleanup:
240
+ git_buf_free(&remote_master_name);
137
241
  git_buf_free(&head_info.branchname);
138
242
  return retcode;
139
243
  }
@@ -156,7 +260,7 @@ static int setup_remotes_and_fetch(git_repository *repo,
156
260
  if (!fetch_stats) fetch_stats = &dummy_stats;
157
261
 
158
262
  /* Create the "origin" remote */
159
- if (!git_remote_add(&origin, repo, "origin", origin_url)) {
263
+ if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) {
160
264
  /* Connect and download everything */
161
265
  if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
162
266
  if (!git_remote_download(origin, &bytes, fetch_stats)) {
@@ -189,12 +293,28 @@ static bool path_is_okay(const char *path)
189
293
  return true;
190
294
  }
191
295
 
296
+ static bool should_checkout(
297
+ git_repository *repo,
298
+ bool is_bare,
299
+ git_checkout_opts *opts)
300
+ {
301
+ if (is_bare)
302
+ return false;
192
303
 
193
- static int clone_internal(git_repository **out,
194
- const char *origin_url,
195
- const char *path,
196
- git_indexer_stats *fetch_stats,
197
- int is_bare)
304
+ if (!opts)
305
+ return false;
306
+
307
+ return !git_repository_head_orphan(repo);
308
+ }
309
+
310
+ static int clone_internal(
311
+ git_repository **out,
312
+ const char *origin_url,
313
+ const char *path,
314
+ git_indexer_stats *fetch_stats,
315
+ git_indexer_stats *checkout_stats,
316
+ git_checkout_opts *checkout_opts,
317
+ bool is_bare)
198
318
  {
199
319
  int retcode = GIT_ERROR;
200
320
  git_repository *repo = NULL;
@@ -210,13 +330,16 @@ static int clone_internal(git_repository **out,
210
330
  if ((retcode = setup_remotes_and_fetch(repo, origin_url, fetch_stats)) < 0) {
211
331
  /* Failed to fetch; clean up */
212
332
  git_repository_free(repo);
213
- git_futils_rmdir_r(path, GIT_DIRREMOVAL_FILES_AND_DIRS);
333
+ git_futils_rmdir_r(path, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
214
334
  } else {
215
335
  *out = repo;
216
336
  retcode = 0;
217
337
  }
218
338
  }
219
339
 
340
+ if (!retcode && should_checkout(repo, is_bare, checkout_opts))
341
+ retcode = git_checkout_head(*out, checkout_opts, checkout_stats);
342
+
220
343
  return retcode;
221
344
  }
222
345
 
@@ -226,7 +349,15 @@ int git_clone_bare(git_repository **out,
226
349
  git_indexer_stats *fetch_stats)
227
350
  {
228
351
  assert(out && origin_url && dest_path);
229
- return clone_internal(out, origin_url, dest_path, fetch_stats, 1);
352
+
353
+ return clone_internal(
354
+ out,
355
+ origin_url,
356
+ dest_path,
357
+ fetch_stats,
358
+ NULL,
359
+ NULL,
360
+ 1);
230
361
  }
231
362
 
232
363
 
@@ -237,18 +368,14 @@ int git_clone(git_repository **out,
237
368
  git_indexer_stats *checkout_stats,
238
369
  git_checkout_opts *checkout_opts)
239
370
  {
240
- int retcode = GIT_ERROR;
241
-
242
371
  assert(out && origin_url && workdir_path);
243
372
 
244
- if (!(retcode = clone_internal(out, origin_url, workdir_path, fetch_stats, 0))) {
245
- retcode = git_checkout_head(*out, checkout_opts, checkout_stats);
246
- }
247
-
248
- return retcode;
373
+ return clone_internal(
374
+ out,
375
+ origin_url,
376
+ workdir_path,
377
+ fetch_stats,
378
+ checkout_stats,
379
+ checkout_opts,
380
+ 0);
249
381
  }
250
-
251
-
252
-
253
-
254
- GIT_END_DECL
@@ -49,14 +49,24 @@
49
49
 
50
50
  #include <regex.h>
51
51
 
52
+ /**
53
+ * Check a pointer allocation result, returning -1 if it failed.
54
+ */
52
55
  #define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
53
56
 
54
- void giterr_set_oom(void);
57
+ /**
58
+ * Set the error message for this thread, formatting as needed.
59
+ */
55
60
  void giterr_set(int error_class, const char *string, ...);
56
- void giterr_clear(void);
57
- void giterr_set_str(int error_class, const char *string);
61
+
62
+ /**
63
+ * Set the error message for a regex failure, using the internal regex
64
+ * error code lookup.
65
+ */
58
66
  void giterr_set_regex(const regex_t *regex, int error_code);
59
67
 
68
+ /* NOTE: other giterr functions are in the public errors.h header file */
69
+
60
70
  #include "util.h"
61
71
 
62
72
  typedef struct git_transport git_transport;
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright (C) 2009-2012 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "compress.h"
9
+
10
+ #include <zlib.h>
11
+
12
+ #define BUFFER_SIZE (1024 * 1024)
13
+
14
+ int git__compress(git_buf *buf, const void *buff, size_t len)
15
+ {
16
+ z_stream zs;
17
+ char *zb;
18
+ size_t have;
19
+
20
+ memset(&zs, 0, sizeof(zs));
21
+ if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK)
22
+ return -1;
23
+
24
+ zb = git__malloc(BUFFER_SIZE);
25
+ GITERR_CHECK_ALLOC(zb);
26
+
27
+ zs.next_in = (void *)buff;
28
+ zs.avail_in = (uInt)len;
29
+
30
+ do {
31
+ zs.next_out = (unsigned char *)zb;
32
+ zs.avail_out = BUFFER_SIZE;
33
+
34
+ if (deflate(&zs, Z_FINISH) == Z_STREAM_ERROR) {
35
+ git__free(zb);
36
+ return -1;
37
+ }
38
+
39
+ have = BUFFER_SIZE - (size_t)zs.avail_out;
40
+
41
+ if (git_buf_put(buf, zb, have) < 0) {
42
+ git__free(zb);
43
+ return -1;
44
+ }
45
+
46
+ } while (zs.avail_out == 0);
47
+
48
+ assert(zs.avail_in == 0);
49
+
50
+ deflateEnd(&zs);
51
+ git__free(zb);
52
+ return 0;
53
+ }