rugged 0.25.0b2 → 0.25.0b3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/rugged/extconf.rb +3 -1
  4. data/ext/rugged/rugged.c +1 -1
  5. data/ext/rugged/rugged.h +1 -1
  6. data/ext/rugged/rugged_blob.c +29 -38
  7. data/ext/rugged/rugged_commit.c +215 -78
  8. data/ext/rugged/rugged_rebase.c +18 -11
  9. data/ext/rugged/rugged_remote.c +2 -2
  10. data/ext/rugged/rugged_tree.c +132 -0
  11. data/lib/rugged/version.rb +1 -1
  12. data/vendor/libgit2/CMakeLists.txt +11 -3
  13. data/vendor/libgit2/include/git2.h +1 -0
  14. data/vendor/libgit2/include/git2/blob.h +39 -28
  15. data/vendor/libgit2/include/git2/commit.h +30 -0
  16. data/vendor/libgit2/include/git2/common.h +16 -1
  17. data/vendor/libgit2/include/git2/merge.h +10 -1
  18. data/vendor/libgit2/include/git2/proxy.h +92 -0
  19. data/vendor/libgit2/include/git2/refs.h +11 -0
  20. data/vendor/libgit2/include/git2/remote.h +17 -4
  21. data/vendor/libgit2/include/git2/signature.h +13 -0
  22. data/vendor/libgit2/include/git2/sys/merge.h +177 -0
  23. data/vendor/libgit2/include/git2/sys/remote.h +16 -0
  24. data/vendor/libgit2/include/git2/sys/stream.h +2 -1
  25. data/vendor/libgit2/include/git2/sys/transport.h +3 -1
  26. data/vendor/libgit2/include/git2/tag.h +9 -0
  27. data/vendor/libgit2/include/git2/tree.h +55 -0
  28. data/vendor/libgit2/src/annotated_commit.c +99 -80
  29. data/vendor/libgit2/src/annotated_commit.h +5 -2
  30. data/vendor/libgit2/src/array.h +40 -0
  31. data/vendor/libgit2/src/blame.c +8 -3
  32. data/vendor/libgit2/src/blame_git.c +2 -1
  33. data/vendor/libgit2/src/blob.c +71 -39
  34. data/vendor/libgit2/src/branch.c +2 -1
  35. data/vendor/libgit2/src/checkout.c +66 -42
  36. data/vendor/libgit2/src/commit.c +67 -3
  37. data/vendor/libgit2/src/config_cache.c +2 -1
  38. data/vendor/libgit2/src/config_file.c +32 -27
  39. data/vendor/libgit2/src/curl_stream.c +89 -6
  40. data/vendor/libgit2/src/delta-apply.c +36 -5
  41. data/vendor/libgit2/src/delta-apply.h +12 -0
  42. data/vendor/libgit2/src/describe.c +3 -2
  43. data/vendor/libgit2/src/diff.c +13 -20
  44. data/vendor/libgit2/src/diff_tform.c +5 -3
  45. data/vendor/libgit2/src/filebuf.c +12 -2
  46. data/vendor/libgit2/src/filebuf.h +1 -0
  47. data/vendor/libgit2/src/fnmatch.c +18 -5
  48. data/vendor/libgit2/src/global.c +18 -0
  49. data/vendor/libgit2/src/global.h +1 -0
  50. data/vendor/libgit2/src/ignore.c +11 -3
  51. data/vendor/libgit2/src/index.c +11 -5
  52. data/vendor/libgit2/src/indexer.c +11 -7
  53. data/vendor/libgit2/src/iterator.c +1575 -1468
  54. data/vendor/libgit2/src/iterator.h +52 -69
  55. data/vendor/libgit2/src/merge.c +160 -63
  56. data/vendor/libgit2/src/merge.h +61 -2
  57. data/vendor/libgit2/src/merge_driver.c +397 -0
  58. data/vendor/libgit2/src/merge_driver.h +60 -0
  59. data/vendor/libgit2/src/merge_file.c +11 -49
  60. data/vendor/libgit2/src/netops.c +12 -10
  61. data/vendor/libgit2/src/object.c +3 -6
  62. data/vendor/libgit2/src/object_api.c +19 -1
  63. data/vendor/libgit2/src/odb_loose.c +1 -1
  64. data/vendor/libgit2/src/openssl_stream.c +16 -3
  65. data/vendor/libgit2/src/pack-objects.c +3 -1
  66. data/vendor/libgit2/src/pack.c +5 -9
  67. data/vendor/libgit2/src/path.c +14 -0
  68. data/vendor/libgit2/src/path.h +12 -0
  69. data/vendor/libgit2/src/pathspec.c +1 -1
  70. data/vendor/libgit2/src/posix.c +7 -0
  71. data/vendor/libgit2/src/posix.h +1 -0
  72. data/vendor/libgit2/src/proxy.c +32 -0
  73. data/vendor/libgit2/src/proxy.h +14 -0
  74. data/vendor/libgit2/src/push.c +7 -7
  75. data/vendor/libgit2/src/rebase.c +61 -31
  76. data/vendor/libgit2/src/refdb_fs.c +1 -0
  77. data/vendor/libgit2/src/refs.c +16 -1
  78. data/vendor/libgit2/src/remote.c +20 -6
  79. data/vendor/libgit2/src/repository.c +1 -1
  80. data/vendor/libgit2/src/reset.c +1 -1
  81. data/vendor/libgit2/src/settings.c +23 -1
  82. data/vendor/libgit2/src/signature.c +26 -1
  83. data/vendor/libgit2/src/stransport_stream.c +5 -2
  84. data/vendor/libgit2/src/stream.h +2 -2
  85. data/vendor/libgit2/src/submodule.c +3 -2
  86. data/vendor/libgit2/src/tag.c +8 -2
  87. data/vendor/libgit2/src/transports/http.c +32 -9
  88. data/vendor/libgit2/src/transports/local.c +4 -1
  89. data/vendor/libgit2/src/transports/smart.c +6 -0
  90. data/vendor/libgit2/src/transports/smart.h +1 -0
  91. data/vendor/libgit2/src/transports/smart_protocol.c +61 -17
  92. data/vendor/libgit2/src/transports/winhttp.c +130 -11
  93. data/vendor/libgit2/src/tree.c +329 -98
  94. data/vendor/libgit2/src/tree.h +4 -5
  95. data/vendor/libgit2/src/unix/map.c +5 -0
  96. data/vendor/libgit2/src/win32/map.c +24 -5
  97. data/vendor/libgit2/src/xdiff/xprepare.c +2 -1
  98. metadata +10 -4
  99. data/vendor/libgit2/Makefile.embed +0 -60
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "git2/common.h"
11
11
  #include "git2/types.h"
12
+ #include "git2/proxy.h"
12
13
 
13
14
  GIT_BEGIN_DECL
14
15
 
@@ -32,7 +33,7 @@ typedef struct git_stream {
32
33
  int proxy_support;
33
34
  int (*connect)(struct git_stream *);
34
35
  int (*certificate)(git_cert **, struct git_stream *);
35
- int (*set_proxy)(struct git_stream *, const char *proxy_url);
36
+ int (*set_proxy)(struct git_stream *, const git_proxy_options *proxy_opts);
36
37
  ssize_t (*read)(struct git_stream *, void *, size_t);
37
38
  ssize_t (*write)(struct git_stream *, const char *, size_t, int);
38
39
  int (*close)(struct git_stream *);
@@ -11,6 +11,7 @@
11
11
  #include "git2/net.h"
12
12
  #include "git2/types.h"
13
13
  #include "git2/strarray.h"
14
+ #include "git2/proxy.h"
14
15
 
15
16
  /**
16
17
  * @file git2/sys/transport.h
@@ -53,6 +54,7 @@ struct git_transport {
53
54
  const char *url,
54
55
  git_cred_acquire_cb cred_acquire_cb,
55
56
  void *cred_acquire_payload,
57
+ const git_proxy_options *proxy_opts,
56
58
  int direction,
57
59
  int flags);
58
60
 
@@ -65,7 +67,7 @@ struct git_transport {
65
67
  git_transport *transport);
66
68
 
67
69
  /* Executes the push whose context is in the git_push object. */
68
- int (*push)(git_transport *transport, git_push *push, const git_remote_callbacks *callbacks);
70
+ int(*push)(git_transport *transport, git_push *push, const git_remote_callbacks *callbacks);
69
71
 
70
72
  /* This function may be called after a successful call to connect(), when
71
73
  * the direction is FETCH. The function performs a negotiation to calculate
@@ -347,6 +347,15 @@ GIT_EXTERN(int) git_tag_peel(
347
347
  git_object **tag_target_out,
348
348
  const git_tag *tag);
349
349
 
350
+ /**
351
+ * Create an in-memory copy of a tag. The copy must be explicitly
352
+ * free'd or it will leak.
353
+ *
354
+ * @param out Pointer to store the copy of the tag
355
+ * @param source Original tag to copy
356
+ */
357
+ GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source);
358
+
350
359
  /** @} */
351
360
  GIT_END_DECL
352
361
  #endif
@@ -409,6 +409,61 @@ GIT_EXTERN(int) git_tree_walk(
409
409
  git_treewalk_cb callback,
410
410
  void *payload);
411
411
 
412
+ /**
413
+ * Create an in-memory copy of a tree. The copy must be explicitly
414
+ * free'd or it will leak.
415
+ *
416
+ * @param out Pointer to store the copy of the tree
417
+ * @param source Original tree to copy
418
+ */
419
+ GIT_EXTERN(int) git_tree_dup(git_tree **out, git_tree *source);
420
+
421
+ /**
422
+ * The kind of update to perform
423
+ */
424
+ typedef enum {
425
+ /** Update or insert an entry at the specified path */
426
+ GIT_TREE_UPDATE_UPSERT,
427
+ /** Remove an entry from the specified path */
428
+ GIT_TREE_UPDATE_REMOVE,
429
+ } git_tree_update_t;
430
+
431
+ /**
432
+ * An action to perform during the update of a tree
433
+ */
434
+ typedef struct {
435
+ /** Update action. If it's an removal, only the path is looked at */
436
+ git_tree_update_t action;
437
+ /** The entry's id */
438
+ git_oid id;
439
+ /** The filemode/kind of object */
440
+ git_filemode_t filemode;
441
+ /** The full path from the root tree */
442
+ const char *path;
443
+ } git_tree_update;
444
+
445
+ /**
446
+ * Create a tree based on another one with the specified modifications
447
+ *
448
+ * Given the `baseline` perform the changes described in the list of
449
+ * `updates` and create a new tree.
450
+ *
451
+ * This function is optimized for common file/directory addition, removal and
452
+ * replacement in trees. It is much more efficient than reading the tree into a
453
+ * `git_index` and modifying that, but in exchange it is not as flexible.
454
+ *
455
+ * Deleting and adding the same entry is undefined behaviour, changing
456
+ * a tree to a blob or viceversa is not supported.
457
+ *
458
+ * @param out id of the new tree
459
+ * @param repo the repository in which to create the tree, must be the
460
+ * same as for `baseline`
461
+ * @param baseline the tree to base these changes on
462
+ * @param nupdates the number of elements in the update list
463
+ * @param updates the list of updates to perform
464
+ */
465
+ GIT_EXTERN(int) git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseline, size_t nupdates, const git_tree_update *updates);
466
+
412
467
  /** @} */
413
468
 
414
469
  GIT_END_DECL
@@ -19,39 +19,102 @@
19
19
  #include "git2/index.h"
20
20
 
21
21
  static int annotated_commit_init(
22
+ git_annotated_commit **out,
23
+ git_commit *commit,
24
+ const char *description)
25
+ {
26
+ git_annotated_commit *annotated_commit;
27
+ int error = 0;
28
+
29
+ assert(out && commit);
30
+
31
+ *out = NULL;
32
+
33
+ annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
34
+ GITERR_CHECK_ALLOC(annotated_commit);
35
+
36
+ annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL;
37
+
38
+ if ((error = git_commit_dup(&annotated_commit->commit, commit)) < 0)
39
+ goto done;
40
+
41
+ git_oid_fmt(annotated_commit->id_str, git_commit_id(commit));
42
+ annotated_commit->id_str[GIT_OID_HEXSZ] = '\0';
43
+
44
+ if (!description)
45
+ description = annotated_commit->id_str;
46
+
47
+ annotated_commit->description = git__strdup(description);
48
+ GITERR_CHECK_ALLOC(annotated_commit->description);
49
+
50
+ done:
51
+ if (!error)
52
+ *out = annotated_commit;
53
+
54
+ return error;
55
+ }
56
+
57
+ static int annotated_commit_init_from_id(
22
58
  git_annotated_commit **out,
23
59
  git_repository *repo,
24
60
  const git_oid *id,
25
- const char *ref_name,
26
- const char *remote_url)
61
+ const char *description)
27
62
  {
28
- git_annotated_commit *annotated_commit;
29
63
  git_commit *commit = NULL;
30
64
  int error = 0;
31
65
 
32
- assert(out && id);
66
+ assert(out && repo && id);
33
67
 
34
68
  *out = NULL;
35
69
 
36
- if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
37
- (error = git_annotated_commit_from_commit(&annotated_commit,
38
- commit)) < 0)
70
+ if ((error = git_commit_lookup(&commit, repo, id)) < 0)
39
71
  goto done;
40
72
 
41
- if (ref_name) {
42
- annotated_commit->ref_name = git__strdup(ref_name);
43
- GITERR_CHECK_ALLOC(annotated_commit->ref_name);
44
- }
73
+ error = annotated_commit_init(out, commit, description);
74
+
75
+ done:
76
+ git_commit_free(commit);
77
+ return error;
78
+ }
79
+
80
+ int git_annotated_commit_lookup(
81
+ git_annotated_commit **out,
82
+ git_repository *repo,
83
+ const git_oid *id)
84
+ {
85
+ return annotated_commit_init_from_id(out, repo, id, NULL);
86
+ }
87
+
88
+ int git_annotated_commit_from_commit(
89
+ git_annotated_commit **out,
90
+ git_commit *commit)
91
+ {
92
+ return annotated_commit_init(out, commit, NULL);
93
+ }
45
94
 
46
- if (remote_url) {
47
- annotated_commit->remote_url = git__strdup(remote_url);
48
- GITERR_CHECK_ALLOC(annotated_commit->remote_url);
95
+ int git_annotated_commit_from_revspec(
96
+ git_annotated_commit **out,
97
+ git_repository *repo,
98
+ const char *revspec)
99
+ {
100
+ git_object *obj, *commit;
101
+ int error;
102
+
103
+ assert(out && repo && revspec);
104
+
105
+ if ((error = git_revparse_single(&obj, repo, revspec)) < 0)
106
+ return error;
107
+
108
+ if ((error = git_object_peel(&commit, obj, GIT_OBJ_COMMIT))) {
109
+ git_object_free(obj);
110
+ return error;
49
111
  }
50
112
 
51
- *out = annotated_commit;
113
+ error = annotated_commit_init(out, (git_commit *)commit, revspec);
114
+
115
+ git_object_free(obj);
116
+ git_object_free(commit);
52
117
 
53
- done:
54
- git_commit_free(commit);
55
118
  return error;
56
119
  }
57
120
 
@@ -70,8 +133,15 @@ int git_annotated_commit_from_ref(
70
133
  if ((error = git_reference_resolve(&resolved, ref)) < 0)
71
134
  return error;
72
135
 
73
- error = annotated_commit_init(out, repo, git_reference_target(resolved),
74
- git_reference_name(ref), NULL);
136
+ error = annotated_commit_init_from_id(out,
137
+ repo,
138
+ git_reference_target(resolved),
139
+ git_reference_name(ref));
140
+
141
+ if (!error) {
142
+ (*out)->ref_name = git__strdup(git_reference_name(ref));
143
+ GITERR_CHECK_ALLOC((*out)->ref_name);
144
+ }
75
145
 
76
146
  git_reference_free(resolved);
77
147
  return error;
@@ -97,41 +167,6 @@ int git_annotated_commit_from_head(
97
167
  return error;
98
168
  }
99
169
 
100
- int git_annotated_commit_from_commit(
101
- git_annotated_commit **out,
102
- git_commit *commit)
103
- {
104
- git_annotated_commit *annotated_commit;
105
-
106
- assert(out && commit);
107
-
108
- *out = NULL;
109
-
110
- annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
111
- GITERR_CHECK_ALLOC(annotated_commit);
112
-
113
- annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL;
114
-
115
- git_cached_obj_incref(commit);
116
- annotated_commit->commit = commit;
117
-
118
- git_oid_fmt(annotated_commit->id_str, git_commit_id(commit));
119
- annotated_commit->id_str[GIT_OID_HEXSZ] = '\0';
120
-
121
- *out = annotated_commit;
122
- return 0;
123
- }
124
-
125
- int git_annotated_commit_lookup(
126
- git_annotated_commit **out,
127
- git_repository *repo,
128
- const git_oid *id)
129
- {
130
- assert(out && repo && id);
131
-
132
- return annotated_commit_init(out, repo, id, NULL, NULL);
133
- }
134
-
135
170
  int git_annotated_commit_from_fetchhead(
136
171
  git_annotated_commit **out,
137
172
  git_repository *repo,
@@ -141,33 +176,16 @@ int git_annotated_commit_from_fetchhead(
141
176
  {
142
177
  assert(repo && id && branch_name && remote_url);
143
178
 
144
- return annotated_commit_init(out, repo, id, branch_name, remote_url);
145
- }
146
-
147
- int git_annotated_commit_from_revspec(
148
- git_annotated_commit **out,
149
- git_repository *repo,
150
- const char *revspec)
151
- {
152
- git_object *obj, *commit;
153
- int error;
154
-
155
- assert(out && repo && revspec);
156
-
157
- if ((error = git_revparse_single(&obj, repo, revspec)) < 0)
158
- return error;
159
-
160
- if ((error = git_object_peel(&commit, obj, GIT_OBJ_COMMIT))) {
161
- git_object_free(obj);
162
- return error;
163
- }
179
+ if (annotated_commit_init_from_id(out, repo, id, branch_name) < 0)
180
+ return -1;
164
181
 
165
- error = annotated_commit_init(out, repo, git_object_id(commit), revspec, NULL);
182
+ (*out)->ref_name = git__strdup(branch_name);
183
+ GITERR_CHECK_ALLOC((*out)->ref_name);
166
184
 
167
- git_object_free(obj);
168
- git_object_free(commit);
185
+ (*out)->remote_url = git__strdup(remote_url);
186
+ GITERR_CHECK_ALLOC((*out)->remote_url);
169
187
 
170
- return error;
188
+ return 0;
171
189
  }
172
190
 
173
191
 
@@ -187,8 +205,9 @@ void git_annotated_commit_free(git_annotated_commit *annotated_commit)
187
205
  case GIT_ANNOTATED_COMMIT_REAL:
188
206
  git_commit_free(annotated_commit->commit);
189
207
  git_tree_free(annotated_commit->tree);
190
- git__free(annotated_commit->ref_name);
191
- git__free(annotated_commit->remote_url);
208
+ git__free((char *)annotated_commit->description);
209
+ git__free((char *)annotated_commit->ref_name);
210
+ git__free((char *)annotated_commit->remote_url);
192
211
  break;
193
212
  case GIT_ANNOTATED_COMMIT_VIRTUAL:
194
213
  git_index_free(annotated_commit->index);
@@ -33,8 +33,11 @@ struct git_annotated_commit {
33
33
  git_index *index;
34
34
  git_array_oid_t parents;
35
35
 
36
- char *ref_name;
37
- char *remote_url;
36
+ /* how this commit was looked up */
37
+ const char *description;
38
+
39
+ const char *ref_name;
40
+ const char *remote_url;
38
41
 
39
42
  char id_str[GIT_OID_HEXSZ+1];
40
43
  };
@@ -82,4 +82,44 @@ on_oom:
82
82
 
83
83
  #define git_array_valid_index(a, i) ((i) < (a).size)
84
84
 
85
+ #define git_array_foreach(a, i, element) \
86
+ for ((i) = 0; (i) < (a).size && ((element) = &(a).ptr[(i)]); (i)++)
87
+
88
+
89
+ GIT_INLINE(int) git_array__search(
90
+ size_t *out,
91
+ void *array_ptr,
92
+ size_t item_size,
93
+ size_t array_len,
94
+ int (*compare)(const void *, const void *),
95
+ const void *key)
96
+ {
97
+ size_t lim;
98
+ unsigned char *part, *array = array_ptr, *base = array_ptr;
99
+ int cmp = -1;
100
+
101
+ for (lim = array_len; lim != 0; lim >>= 1) {
102
+ part = base + (lim >> 1) * item_size;
103
+ cmp = (*compare)(key, part);
104
+
105
+ if (cmp == 0) {
106
+ base = part;
107
+ break;
108
+ }
109
+ if (cmp > 0) { /* key > p; take right partition */
110
+ base = part + 1 * item_size;
111
+ lim--;
112
+ } /* else take left partition */
113
+ }
114
+
115
+ if (out)
116
+ *out = (base - array) / item_size;
117
+
118
+ return (cmp == 0) ? 0 : GIT_ENOTFOUND;
119
+ }
120
+
121
+ #define git_array_search(out, a, cmp, key) \
122
+ git_array__search(out, (a).ptr, sizeof(*(a).ptr), (a).size, \
123
+ (cmp), (key))
124
+
85
125
  #endif
@@ -178,7 +178,7 @@ const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
178
178
  return NULL;
179
179
  }
180
180
 
181
- static void normalize_options(
181
+ static int normalize_options(
182
182
  git_blame_options *out,
183
183
  const git_blame_options *in,
184
184
  git_repository *repo)
@@ -190,7 +190,9 @@ static void normalize_options(
190
190
 
191
191
  /* No newest_commit => HEAD */
192
192
  if (git_oid_iszero(&out->newest_commit)) {
193
- git_reference_name_to_id(&out->newest_commit, repo, "HEAD");
193
+ if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) {
194
+ return -1;
195
+ }
194
196
  }
195
197
 
196
198
  /* min_line 0 really means 1 */
@@ -204,6 +206,8 @@ static void normalize_options(
204
206
  out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
205
207
  if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES)
206
208
  out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE;
209
+
210
+ return 0;
207
211
  }
208
212
 
209
213
  static git_blame_hunk *split_hunk_in_vector(
@@ -362,7 +366,8 @@ int git_blame_file(
362
366
  git_blame *blame = NULL;
363
367
 
364
368
  assert(out && repo && path);
365
- normalize_options(&normOptions, options, repo);
369
+ if ((error = normalize_options(&normOptions, options, repo)) < 0)
370
+ goto on_error;
366
371
 
367
372
  blame = git_blame__alloc(repo, normOptions, path);
368
373
  GITERR_CHECK_ALLOC(blame);