rugged 0.24.6.1 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/ext/rugged/extconf.rb +9 -2
  4. data/ext/rugged/rugged.c +85 -21
  5. data/ext/rugged/rugged.h +7 -21
  6. data/ext/rugged/rugged_backend.c +3 -20
  7. data/ext/rugged/rugged_blame.c +7 -24
  8. data/ext/rugged/rugged_blob.c +136 -59
  9. data/ext/rugged/rugged_branch.c +3 -20
  10. data/ext/rugged/rugged_branch_collection.c +3 -20
  11. data/ext/rugged/rugged_commit.c +251 -101
  12. data/ext/rugged/rugged_config.c +3 -20
  13. data/ext/rugged/rugged_cred.c +3 -20
  14. data/ext/rugged/rugged_diff.c +3 -20
  15. data/ext/rugged/rugged_diff_delta.c +3 -20
  16. data/ext/rugged/rugged_diff_hunk.c +3 -20
  17. data/ext/rugged/rugged_diff_line.c +3 -20
  18. data/ext/rugged/rugged_index.c +46 -229
  19. data/ext/rugged/rugged_note.c +3 -20
  20. data/ext/rugged/rugged_object.c +3 -20
  21. data/ext/rugged/rugged_patch.c +192 -34
  22. data/ext/rugged/rugged_rebase.c +90 -48
  23. data/ext/rugged/rugged_reference.c +4 -21
  24. data/ext/rugged/rugged_reference_collection.c +3 -20
  25. data/ext/rugged/rugged_remote.c +70 -42
  26. data/ext/rugged/rugged_remote_collection.c +3 -20
  27. data/ext/rugged/rugged_repo.c +50 -59
  28. data/ext/rugged/rugged_revwalk.c +4 -21
  29. data/ext/rugged/rugged_settings.c +3 -20
  30. data/ext/rugged/rugged_signature.c +3 -20
  31. data/ext/rugged/rugged_submodule.c +4 -21
  32. data/ext/rugged/rugged_submodule_collection.c +3 -20
  33. data/ext/rugged/rugged_tag.c +3 -20
  34. data/ext/rugged/rugged_tag_collection.c +3 -20
  35. data/ext/rugged/rugged_tree.c +189 -184
  36. data/lib/rugged/attributes.rb +5 -0
  37. data/lib/rugged/blob.rb +5 -0
  38. data/lib/rugged/branch.rb +6 -1
  39. data/lib/rugged/commit.rb +5 -0
  40. data/lib/rugged/console.rb +5 -0
  41. data/lib/rugged/credentials.rb +5 -0
  42. data/lib/rugged/diff/delta.rb +5 -0
  43. data/lib/rugged/diff/hunk.rb +5 -0
  44. data/lib/rugged/diff/line.rb +5 -0
  45. data/lib/rugged/diff.rb +5 -0
  46. data/lib/rugged/index.rb +120 -0
  47. data/lib/rugged/object.rb +5 -0
  48. data/lib/rugged/patch.rb +5 -0
  49. data/lib/rugged/reference.rb +5 -0
  50. data/lib/rugged/remote.rb +5 -0
  51. data/lib/rugged/repository.rb +9 -4
  52. data/lib/rugged/submodule_collection.rb +5 -0
  53. data/lib/rugged/tag.rb +5 -0
  54. data/lib/rugged/tree.rb +156 -1
  55. data/lib/rugged/version.rb +6 -1
  56. data/lib/rugged/walker.rb +5 -0
  57. data/lib/rugged.rb +5 -0
  58. data/vendor/libgit2/CMakeLists.txt +12 -2
  59. data/vendor/libgit2/include/git2/blob.h +39 -28
  60. data/vendor/libgit2/include/git2/commit.h +76 -0
  61. data/vendor/libgit2/include/git2/common.h +21 -1
  62. data/vendor/libgit2/include/git2/describe.h +5 -2
  63. data/vendor/libgit2/include/git2/diff.h +62 -7
  64. data/vendor/libgit2/include/git2/errors.h +2 -1
  65. data/vendor/libgit2/include/git2/index.h +25 -0
  66. data/vendor/libgit2/include/git2/merge.h +10 -1
  67. data/vendor/libgit2/include/git2/odb.h +47 -1
  68. data/vendor/libgit2/include/git2/pack.h +4 -4
  69. data/vendor/libgit2/include/git2/patch.h +1 -1
  70. data/vendor/libgit2/include/git2/proxy.h +92 -0
  71. data/vendor/libgit2/include/git2/refs.h +11 -0
  72. data/vendor/libgit2/include/git2/remote.h +21 -8
  73. data/vendor/libgit2/include/git2/repository.h +20 -1
  74. data/vendor/libgit2/include/git2/revwalk.h +4 -6
  75. data/vendor/libgit2/include/git2/signature.h +13 -0
  76. data/vendor/libgit2/include/git2/submodule.h +11 -3
  77. data/vendor/libgit2/include/git2/sys/merge.h +177 -0
  78. data/vendor/libgit2/include/git2/sys/odb_backend.h +11 -0
  79. data/vendor/libgit2/include/git2/sys/remote.h +16 -0
  80. data/vendor/libgit2/include/git2/sys/stream.h +2 -1
  81. data/vendor/libgit2/include/git2/sys/time.h +31 -0
  82. data/vendor/libgit2/include/git2/sys/transport.h +3 -1
  83. data/vendor/libgit2/include/git2/tag.h +9 -0
  84. data/vendor/libgit2/include/git2/transaction.h +9 -0
  85. data/vendor/libgit2/include/git2/tree.h +55 -0
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2.h +1 -0
  88. data/vendor/libgit2/src/annotated_commit.c +99 -80
  89. data/vendor/libgit2/src/annotated_commit.h +5 -2
  90. data/vendor/libgit2/src/apply.c +377 -0
  91. data/vendor/libgit2/src/apply.h +21 -0
  92. data/vendor/libgit2/src/array.h +0 -1
  93. data/vendor/libgit2/src/blob.c +71 -39
  94. data/vendor/libgit2/src/branch.c +7 -5
  95. data/vendor/libgit2/src/buffer.c +252 -20
  96. data/vendor/libgit2/src/buffer.h +8 -0
  97. data/vendor/libgit2/src/checkout.c +69 -42
  98. data/vendor/libgit2/src/clone.c +0 -8
  99. data/vendor/libgit2/src/commit.c +193 -49
  100. data/vendor/libgit2/src/commit_list.c +8 -3
  101. data/vendor/libgit2/src/commit_list.h +1 -0
  102. data/vendor/libgit2/src/common.h +2 -1
  103. data/vendor/libgit2/src/config.c +3 -3
  104. data/vendor/libgit2/src/config_file.c +20 -10
  105. data/vendor/libgit2/src/crlf.c +1 -0
  106. data/vendor/libgit2/src/curl_stream.c +106 -6
  107. data/vendor/libgit2/src/delta.c +238 -62
  108. data/vendor/libgit2/src/delta.h +79 -58
  109. data/vendor/libgit2/src/describe.c +1 -1
  110. data/vendor/libgit2/src/diff.c +32 -1554
  111. data/vendor/libgit2/src/diff.h +14 -122
  112. data/vendor/libgit2/src/diff_driver.c +4 -6
  113. data/vendor/libgit2/src/diff_file.c +3 -0
  114. data/vendor/libgit2/src/diff_generate.c +1613 -0
  115. data/vendor/libgit2/src/diff_generate.h +123 -0
  116. data/vendor/libgit2/src/diff_parse.c +101 -0
  117. data/vendor/libgit2/src/diff_parse.h +18 -0
  118. data/vendor/libgit2/src/diff_print.c +263 -144
  119. data/vendor/libgit2/src/diff_stats.c +21 -12
  120. data/vendor/libgit2/src/diff_tform.c +1 -0
  121. data/vendor/libgit2/src/diff_tform.h +22 -0
  122. data/vendor/libgit2/src/diff_xdiff.c +9 -9
  123. data/vendor/libgit2/src/diff_xdiff.h +5 -5
  124. data/vendor/libgit2/src/fetchhead.c +8 -8
  125. data/vendor/libgit2/src/filebuf.c +6 -1
  126. data/vendor/libgit2/src/filebuf.h +1 -0
  127. data/vendor/libgit2/src/fileops.c +22 -1
  128. data/vendor/libgit2/src/fileops.h +8 -2
  129. data/vendor/libgit2/src/fnmatch.c +18 -5
  130. data/vendor/libgit2/src/global.c +21 -4
  131. data/vendor/libgit2/src/global.h +6 -0
  132. data/vendor/libgit2/src/graph.c +1 -1
  133. data/vendor/libgit2/src/index.c +159 -46
  134. data/vendor/libgit2/src/index.h +2 -0
  135. data/vendor/libgit2/src/iterator.c +1573 -1468
  136. data/vendor/libgit2/src/iterator.h +52 -69
  137. data/vendor/libgit2/src/merge.c +163 -64
  138. data/vendor/libgit2/src/merge.h +61 -2
  139. data/vendor/libgit2/src/merge_driver.c +397 -0
  140. data/vendor/libgit2/src/merge_driver.h +60 -0
  141. data/vendor/libgit2/src/merge_file.c +11 -49
  142. data/vendor/libgit2/src/netops.c +12 -10
  143. data/vendor/libgit2/src/object_api.c +19 -1
  144. data/vendor/libgit2/src/odb.c +228 -52
  145. data/vendor/libgit2/src/odb_loose.c +19 -1
  146. data/vendor/libgit2/src/odb_mempack.c +1 -1
  147. data/vendor/libgit2/src/odb_pack.c +27 -1
  148. data/vendor/libgit2/src/openssl_stream.c +4 -5
  149. data/vendor/libgit2/src/pack-objects.c +105 -76
  150. data/vendor/libgit2/src/pack-objects.h +13 -12
  151. data/vendor/libgit2/src/pack.c +16 -10
  152. data/vendor/libgit2/src/pack.h +2 -0
  153. data/vendor/libgit2/src/patch.c +216 -0
  154. data/vendor/libgit2/src/patch.h +66 -0
  155. data/vendor/libgit2/src/{diff_patch.c → patch_generate.c} +203 -376
  156. data/vendor/libgit2/src/patch_generate.h +68 -0
  157. data/vendor/libgit2/src/patch_parse.c +1159 -0
  158. data/vendor/libgit2/src/patch_parse.h +56 -0
  159. data/vendor/libgit2/src/path.c +38 -2
  160. data/vendor/libgit2/src/path.h +18 -0
  161. data/vendor/libgit2/src/pathspec.c +1 -1
  162. data/vendor/libgit2/src/pool.h +5 -0
  163. data/vendor/libgit2/src/pqueue.c +12 -5
  164. data/vendor/libgit2/src/pqueue.h +1 -0
  165. data/vendor/libgit2/src/proxy.c +32 -0
  166. data/vendor/libgit2/src/proxy.h +14 -0
  167. data/vendor/libgit2/src/push.c +1 -1
  168. data/vendor/libgit2/src/rebase.c +63 -36
  169. data/vendor/libgit2/src/refdb.c +4 -2
  170. data/vendor/libgit2/src/refdb_fs.c +82 -54
  171. data/vendor/libgit2/src/refs.c +13 -1
  172. data/vendor/libgit2/src/remote.c +20 -81
  173. data/vendor/libgit2/src/repository.c +212 -29
  174. data/vendor/libgit2/src/reset.c +1 -1
  175. data/vendor/libgit2/src/revparse.c +1 -1
  176. data/vendor/libgit2/src/revwalk.c +260 -184
  177. data/vendor/libgit2/src/settings.c +11 -3
  178. data/vendor/libgit2/src/signature.c +27 -2
  179. data/vendor/libgit2/src/sortedcache.c +14 -5
  180. data/vendor/libgit2/src/stash.c +1 -0
  181. data/vendor/libgit2/src/status.c +1 -0
  182. data/vendor/libgit2/src/stransport_stream.c +4 -2
  183. data/vendor/libgit2/src/stream.h +2 -2
  184. data/vendor/libgit2/src/submodule.c +16 -4
  185. data/vendor/libgit2/src/sysdir.c +1 -1
  186. data/vendor/libgit2/src/transport.c +3 -5
  187. data/vendor/libgit2/src/transports/http.c +38 -13
  188. data/vendor/libgit2/src/transports/local.c +4 -1
  189. data/vendor/libgit2/src/transports/smart.c +6 -0
  190. data/vendor/libgit2/src/transports/smart.h +1 -0
  191. data/vendor/libgit2/src/transports/smart_pkt.c +5 -13
  192. data/vendor/libgit2/src/transports/smart_protocol.c +22 -7
  193. data/vendor/libgit2/src/transports/winhttp.c +144 -11
  194. data/vendor/libgit2/src/tree.c +267 -2
  195. data/vendor/libgit2/src/unix/posix.h +10 -0
  196. data/vendor/libgit2/src/unix/pthread.h +2 -0
  197. data/vendor/libgit2/src/util.c +25 -2
  198. data/vendor/libgit2/src/util.h +10 -0
  199. data/vendor/libgit2/src/varint.c +44 -0
  200. data/vendor/libgit2/src/varint.h +15 -0
  201. data/vendor/libgit2/src/vector.c +58 -0
  202. data/vendor/libgit2/src/vector.h +8 -0
  203. data/vendor/libgit2/src/win32/posix.h +3 -0
  204. data/vendor/libgit2/src/win32/thread.c +18 -0
  205. data/vendor/libgit2/src/win32/thread.h +2 -0
  206. data/vendor/libgit2/src/win32/w32_util.h +1 -1
  207. data/vendor/libgit2/src/zstream.c +37 -8
  208. data/vendor/libgit2/src/zstream.h +8 -1
  209. metadata +100 -82
  210. data/vendor/libgit2/Makefile.embed +0 -60
  211. data/vendor/libgit2/src/delta-apply.c +0 -166
  212. data/vendor/libgit2/src/delta-apply.h +0 -62
  213. data/vendor/libgit2/src/diff_patch.h +0 -83
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
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
+ #ifndef INCLUDE_patch_parse_h__
8
+ #define INCLUDE_patch_parse_h__
9
+
10
+ typedef struct {
11
+ git_refcount rc;
12
+
13
+ /* Original content buffer */
14
+ const char *content;
15
+ size_t content_len;
16
+
17
+ git_patch_options opts;
18
+
19
+ /* The remaining (unparsed) buffer */
20
+ const char *remain;
21
+ size_t remain_len;
22
+
23
+ const char *line;
24
+ size_t line_len;
25
+ size_t line_num;
26
+ } git_patch_parse_ctx;
27
+
28
+ extern git_patch_parse_ctx *git_patch_parse_ctx_init(
29
+ const char *content,
30
+ size_t content_len,
31
+ const git_patch_options *opts);
32
+
33
+ extern void git_patch_parse_ctx_free(git_patch_parse_ctx *ctx);
34
+
35
+ /**
36
+ * Create a patch for a single file from the contents of a patch buffer.
37
+ *
38
+ * @param out The patch to be created
39
+ * @param contents The contents of a patch file
40
+ * @param contents_len The length of the patch file
41
+ * @param opts The git_patch_options
42
+ * @return 0 on success, <0 on failure.
43
+ */
44
+ extern int git_patch_from_buffer(
45
+ git_patch **out,
46
+ const char *contents,
47
+ size_t contents_len,
48
+ const git_patch_options *opts);
49
+
50
+ extern int git_patch_parse(
51
+ git_patch **out,
52
+ git_patch_parse_ctx *ctx);
53
+
54
+ extern int git_patch_parsed_from_diff(git_patch **, git_diff *, size_t);
55
+
56
+ #endif
@@ -306,6 +306,25 @@ int git_path_join_unrooted(
306
306
  return 0;
307
307
  }
308
308
 
309
+ void git_path_squash_slashes(git_buf *path)
310
+ {
311
+ char *p, *q;
312
+
313
+ if (path->size == 0)
314
+ return;
315
+
316
+ for (p = path->ptr, q = path->ptr; *q; p++, q++) {
317
+ *p = *q;
318
+
319
+ while (*q == '/' && *(q+1) == '/') {
320
+ path->size--;
321
+ q++;
322
+ }
323
+ }
324
+
325
+ *p = '\0';
326
+ }
327
+
309
328
  int git_path_prettify(git_buf *path_out, const char *path, const char *base)
310
329
  {
311
330
  char buf[GIT_PATH_MAX];
@@ -625,6 +644,10 @@ int git_path_set_error(int errno_value, const char *path, const char *action)
625
644
  giterr_set(GITERR_OS, "Failed %s - '%s' already exists", action, path);
626
645
  return GIT_EEXISTS;
627
646
 
647
+ case EACCES:
648
+ giterr_set(GITERR_OS, "Failed %s - '%s' is locked", action, path);
649
+ return GIT_ELOCKED;
650
+
628
651
  default:
629
652
  giterr_set(GITERR_OS, "Could not %s '%s'", action, path);
630
653
  return -1;
@@ -810,6 +833,20 @@ int git_path_cmp(
810
833
  return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
811
834
  }
812
835
 
836
+ size_t git_path_common_dirlen(const char *one, const char *two)
837
+ {
838
+ const char *p, *q, *dirsep = NULL;
839
+
840
+ for (p = one, q = two; *p && *q; p++, q++) {
841
+ if (*p == '/' && *q == '/')
842
+ dirsep = p;
843
+ else if (*p != *q)
844
+ break;
845
+ }
846
+
847
+ return dirsep ? (dirsep - one) + 1 : 0;
848
+ }
849
+
813
850
  int git_path_make_relative(git_buf *path, const char *parent)
814
851
  {
815
852
  const char *p, *q, *p_dirsep, *q_dirsep;
@@ -1108,7 +1145,6 @@ int git_path_diriter_init(
1108
1145
  unsigned int flags)
1109
1146
  {
1110
1147
  git_win32_path path_filter;
1111
- git_buf hack = {0};
1112
1148
 
1113
1149
  static int is_win7_or_later = -1;
1114
1150
  if (is_win7_or_later < 0)
@@ -1314,7 +1350,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
1314
1350
  return GIT_ITEROVER;
1315
1351
 
1316
1352
  giterr_set(GITERR_OS,
1317
- "Could not read directory '%s'", diriter->path);
1353
+ "Could not read directory '%s'", diriter->path.ptr);
1318
1354
  return -1;
1319
1355
  }
1320
1356
  } while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));
@@ -202,6 +202,18 @@ extern bool git_path_contains(git_buf *dir, const char *item);
202
202
  */
203
203
  extern bool git_path_contains_dir(git_buf *parent, const char *subdir);
204
204
 
205
+ /**
206
+ * Determine the common directory length between two paths, including
207
+ * the final path separator. For example, given paths 'a/b/c/1.txt
208
+ * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
209
+ * will return the length of the string 'a/b/c/', which is 6.
210
+ *
211
+ * @param one The first path
212
+ * @param two The second path
213
+ * @return The length of the common directory
214
+ */
215
+ extern size_t git_path_common_dirlen(const char *one, const char *two);
216
+
205
217
  /**
206
218
  * Make the path relative to the given parent path.
207
219
  *
@@ -231,6 +243,12 @@ extern bool git_path_contains_file(git_buf *dir, const char *file);
231
243
  extern int git_path_join_unrooted(
232
244
  git_buf *path_out, const char *path, const char *base, ssize_t *root_at);
233
245
 
246
+ /**
247
+ * Removes multiple occurrences of '/' in a row, squashing them into a
248
+ * single '/'.
249
+ */
250
+ extern void git_path_squash_slashes(git_buf *path);
251
+
234
252
  /**
235
253
  * Clean up path, prepending base if it is not already rooted.
236
254
  */
@@ -418,7 +418,7 @@ static int pathspec_match_from_iterator(
418
418
  GITERR_CHECK_ALLOC(m);
419
419
  }
420
420
 
421
- if ((error = git_iterator_reset(iter, ps->prefix, ps->prefix)) < 0)
421
+ if ((error = git_iterator_reset_range(iter, ps->prefix, ps->prefix)) < 0)
422
422
  goto done;
423
423
 
424
424
  if (git_iterator_type(iter) == GIT_ITERATOR_TYPE_WORKDIR &&
@@ -35,6 +35,8 @@ typedef struct {
35
35
  uint32_t page_size; /* size of page in bytes */
36
36
  } git_pool;
37
37
 
38
+ #define GIT_POOL_INIT { NULL, 0, 0 }
39
+
38
40
  #else
39
41
 
40
42
  /**
@@ -57,6 +59,9 @@ typedef struct {
57
59
  uint32_t item_size;
58
60
  uint32_t page_size;
59
61
  } git_pool;
62
+
63
+ #define GIT_POOL_INIT { GIT_VECTOR_INIT, 0, 0 }
64
+
60
65
  #endif
61
66
 
62
67
  /**
@@ -86,14 +86,15 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
86
86
  if ((pq->flags & GIT_PQUEUE_FIXED_SIZE) != 0 &&
87
87
  pq->length >= pq->_alloc_size)
88
88
  {
89
- /* skip this item if below min item in heap */
90
- if (pq->_cmp(item, git_vector_get(pq, 0)) <= 0)
89
+ /* skip this item if below min item in heap or if
90
+ * we do not have a comparison function */
91
+ if (!pq->_cmp || pq->_cmp(item, git_vector_get(pq, 0)) <= 0)
91
92
  return 0;
92
93
  /* otherwise remove the min item before inserting new */
93
94
  (void)git_pqueue_pop(pq);
94
95
  }
95
96
 
96
- if (!(error = git_vector_insert(pq, item)))
97
+ if (!(error = git_vector_insert(pq, item)) && pq->_cmp)
97
98
  pqueue_up(pq, pq->length - 1);
98
99
 
99
100
  return error;
@@ -101,9 +102,15 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
101
102
 
102
103
  void *git_pqueue_pop(git_pqueue *pq)
103
104
  {
104
- void *rval = git_pqueue_get(pq, 0);
105
+ void *rval;
105
106
 
106
- if (git_pqueue_size(pq) > 1) {
107
+ if (!pq->_cmp) {
108
+ rval = git_vector_last(pq);
109
+ } else {
110
+ rval = git_pqueue_get(pq, 0);
111
+ }
112
+
113
+ if (git_pqueue_size(pq) > 1 && pq->_cmp) {
107
114
  /* move last item to top of heap, shrink, and push item down */
108
115
  pq->contents[0] = git_vector_last(pq);
109
116
  git_vector_pop(pq);
@@ -35,6 +35,7 @@ extern int git_pqueue_init(
35
35
  #define git_pqueue_clear git_vector_clear
36
36
  #define git_pqueue_size git_vector_length
37
37
  #define git_pqueue_get git_vector_get
38
+ #define git_pqueue_reverse git_vector_reverse
38
39
 
39
40
  /**
40
41
  * Insert a new item into the queue
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
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 "common.h"
9
+ #include "git2/proxy.h"
10
+
11
+ int git_proxy_init_options(git_proxy_options *opts, unsigned int version)
12
+ {
13
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
14
+ opts, version, git_proxy_options, GIT_PROXY_OPTIONS_INIT);
15
+ return 0;
16
+ }
17
+
18
+ int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src)
19
+ {
20
+ if (!src) {
21
+ git_proxy_init_options(tgt, GIT_PROXY_OPTIONS_VERSION);
22
+ return 0;
23
+ }
24
+
25
+ memcpy(tgt, src, sizeof(git_proxy_options));
26
+ if (src->url) {
27
+ tgt->url = git__strdup(src->url);
28
+ GITERR_CHECK_ALLOC(tgt->url);
29
+ }
30
+
31
+ return 0;
32
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
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
+ #ifndef INCLUDE_proxy_h__
8
+ #define INCLUDE_proxy_h__
9
+
10
+ #include "git2/proxy.h"
11
+
12
+ extern int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src);
13
+
14
+ #endif
@@ -639,7 +639,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
639
639
  int error;
640
640
 
641
641
  if (!git_remote_connected(push->remote) &&
642
- (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH, callbacks, push->custom_headers)) < 0)
642
+ (error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH, callbacks, NULL, push->custom_headers)) < 0)
643
643
  return error;
644
644
 
645
645
  if ((error = filter_refs(push->remote)) < 0 ||
@@ -472,6 +472,7 @@ done:
472
472
  static int rebase_setupfiles(git_rebase *rebase)
473
473
  {
474
474
  char onto[GIT_OID_HEXSZ], orig_head[GIT_OID_HEXSZ];
475
+ const char *orig_head_name;
475
476
 
476
477
  git_oid_fmt(onto, &rebase->onto_id);
477
478
  git_oid_fmt(orig_head, &rebase->orig_head_id);
@@ -481,8 +482,11 @@ static int rebase_setupfiles(git_rebase *rebase)
481
482
  return -1;
482
483
  }
483
484
 
485
+ orig_head_name = rebase->head_detached ? ORIG_DETACHED_HEAD :
486
+ rebase->orig_head_name;
487
+
484
488
  if (git_repository__set_orig_head(rebase->repo, &rebase->orig_head_id) < 0 ||
485
- rebase_setupfile(rebase, HEAD_NAME_FILE, -1, "%s\n", rebase->orig_head_name) < 0 ||
489
+ rebase_setupfile(rebase, HEAD_NAME_FILE, -1, "%s\n", orig_head_name) < 0 ||
486
490
  rebase_setupfile(rebase, ONTO_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 ||
487
491
  rebase_setupfile(rebase, ORIG_HEAD_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 ||
488
492
  rebase_setupfile(rebase, QUIET_FILE, -1, rebase->quiet ? "t\n" : "\n") < 0)
@@ -582,7 +586,7 @@ static int rebase_init_operations(
582
586
  (error = git_revwalk_hide(revwalk, git_annotated_commit_id(upstream))) < 0)
583
587
  goto done;
584
588
 
585
- git_revwalk_sorting(revwalk, GIT_SORT_REVERSE | GIT_SORT_TIME);
589
+ git_revwalk_sorting(revwalk, GIT_SORT_REVERSE);
586
590
 
587
591
  while ((error = git_revwalk_next(&id, revwalk)) == 0) {
588
592
  if ((error = git_commit_lookup(&commit, repo, &id)) < 0)
@@ -626,8 +630,12 @@ static int rebase_init_merge(
626
630
  rebase->state_path = git_buf_detach(&state_path);
627
631
  GITERR_CHECK_ALLOC(rebase->state_path);
628
632
 
629
- rebase->orig_head_name = git__strdup(branch->ref_name ? branch->ref_name : ORIG_DETACHED_HEAD);
630
- GITERR_CHECK_ALLOC(rebase->orig_head_name);
633
+ if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
634
+ rebase->orig_head_name = git__strdup(branch->ref_name);
635
+ GITERR_CHECK_ALLOC(rebase->orig_head_name);
636
+ } else {
637
+ rebase->head_detached = 1;
638
+ }
631
639
 
632
640
  rebase->onto_name = git__strdup(rebase_onto_name(onto));
633
641
  GITERR_CHECK_ALLOC(rebase->onto_name);
@@ -844,6 +852,7 @@ static int rebase_next_inmemory(
844
852
  git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL;
845
853
  git_rebase_operation *operation;
846
854
  git_index *index = NULL;
855
+ unsigned int parent_count;
847
856
  int error;
848
857
 
849
858
  *out = NULL;
@@ -851,10 +860,20 @@ static int rebase_next_inmemory(
851
860
  operation = git_array_get(rebase->operations, rebase->current);
852
861
 
853
862
  if ((error = git_commit_lookup(&current_commit, rebase->repo, &operation->id)) < 0 ||
854
- (error = git_commit_tree(&current_tree, current_commit)) < 0 ||
855
- (error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
856
- (error = git_commit_tree(&parent_tree, parent_commit)) < 0 ||
857
- (error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
863
+ (error = git_commit_tree(&current_tree, current_commit)) < 0)
864
+ goto done;
865
+
866
+ if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
867
+ giterr_set(GITERR_REBASE, "Cannot rebase a merge commit");
868
+ error = -1;
869
+ goto done;
870
+ } else if (parent_count) {
871
+ if ((error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
872
+ (error = git_commit_tree(&parent_tree, parent_commit)) < 0)
873
+ goto done;
874
+ }
875
+
876
+ if ((error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
858
877
  (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0)
859
878
  goto done;
860
879
 
@@ -1028,15 +1047,12 @@ static int rebase_commit_inmemory(
1028
1047
  const char *message_encoding,
1029
1048
  const char *message)
1030
1049
  {
1031
- git_rebase_operation *operation;
1032
1050
  git_commit *commit = NULL;
1033
1051
  int error = 0;
1034
1052
 
1035
- operation = git_array_get(rebase->operations, rebase->current);
1036
-
1037
- assert(operation);
1038
1053
  assert(rebase->index);
1039
1054
  assert(rebase->last_commit);
1055
+ assert(rebase->current < rebase->operations.size);
1040
1056
 
1041
1057
  if ((error = rebase_commit__create(&commit, rebase, rebase->index,
1042
1058
  rebase->last_commit, author, committer, message_encoding, message)) < 0)
@@ -1254,42 +1270,33 @@ done:
1254
1270
  return error;
1255
1271
  }
1256
1272
 
1257
- int git_rebase_finish(
1258
- git_rebase *rebase,
1259
- const git_signature *signature)
1273
+ static int return_to_orig_head(git_rebase *rebase)
1260
1274
  {
1261
1275
  git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
1262
1276
  git_commit *terminal_commit = NULL;
1263
1277
  git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT;
1264
1278
  char onto[GIT_OID_HEXSZ];
1265
- int error;
1266
-
1267
- assert(rebase);
1268
-
1269
- if (rebase->inmemory)
1270
- return 0;
1279
+ int error = 0;
1271
1280
 
1272
1281
  git_oid_fmt(onto, &rebase->onto_id);
1273
1282
 
1274
- if ((error = git_buf_printf(&branch_msg, "rebase finished: %s onto %.*s",
1275
- rebase->orig_head_name, GIT_OID_HEXSZ, onto)) < 0 ||
1276
- (error = git_buf_printf(&head_msg, "rebase finished: returning to %s",
1277
- rebase->orig_head_name)) < 0 ||
1278
- (error = git_repository_head(&terminal_ref, rebase->repo)) < 0 ||
1283
+ if ((error = git_buf_printf(&branch_msg,
1284
+ "rebase finished: %s onto %.*s",
1285
+ rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
1286
+ (error = git_buf_printf(&head_msg,
1287
+ "rebase finished: returning to %s",
1288
+ rebase->orig_head_name)) == 0 &&
1289
+ (error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
1279
1290
  (error = git_reference_peel((git_object **)&terminal_commit,
1280
- terminal_ref, GIT_OBJ_COMMIT)) < 0 ||
1291
+ terminal_ref, GIT_OBJ_COMMIT)) == 0 &&
1281
1292
  (error = git_reference_create_matching(&branch_ref,
1282
- rebase->repo, rebase->orig_head_name, git_commit_id(terminal_commit), 1,
1283
- &rebase->orig_head_id, branch_msg.ptr)) < 0 ||
1284
- (error = git_reference_symbolic_create(&head_ref,
1293
+ rebase->repo, rebase->orig_head_name,
1294
+ git_commit_id(terminal_commit), 1,
1295
+ &rebase->orig_head_id, branch_msg.ptr)) == 0)
1296
+ error = git_reference_symbolic_create(&head_ref,
1285
1297
  rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
1286
- head_msg.ptr)) < 0 ||
1287
- (error = rebase_copy_notes(rebase, signature)) < 0)
1288
- goto done;
1298
+ head_msg.ptr);
1289
1299
 
1290
- error = rebase_cleanup(rebase);
1291
-
1292
- done:
1293
1300
  git_buf_free(&head_msg);
1294
1301
  git_buf_free(&branch_msg);
1295
1302
  git_commit_free(terminal_commit);
@@ -1300,6 +1307,26 @@ done:
1300
1307
  return error;
1301
1308
  }
1302
1309
 
1310
+ int git_rebase_finish(
1311
+ git_rebase *rebase,
1312
+ const git_signature *signature)
1313
+ {
1314
+ int error = 0;
1315
+
1316
+ assert(rebase);
1317
+
1318
+ if (rebase->inmemory)
1319
+ return 0;
1320
+
1321
+ if (!rebase->head_detached)
1322
+ error = return_to_orig_head(rebase);
1323
+
1324
+ if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
1325
+ error = rebase_cleanup(rebase);
1326
+
1327
+ return error;
1328
+ }
1329
+
1303
1330
  size_t git_rebase_operation_entrycount(git_rebase *rebase)
1304
1331
  {
1305
1332
  assert(rebase);
@@ -125,13 +125,15 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
125
125
 
126
126
  int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob)
127
127
  {
128
+ int error;
129
+
128
130
  if (!db->backend || !db->backend->iterator) {
129
131
  giterr_set(GITERR_REFERENCE, "This backend doesn't support iterators");
130
132
  return -1;
131
133
  }
132
134
 
133
- if (db->backend->iterator(out, db->backend, glob) < 0)
134
- return -1;
135
+ if ((error = db->backend->iterator(out, db->backend, glob)) < 0)
136
+ return error;
135
137
 
136
138
  GIT_REFCOUNT_INC(db);
137
139
  (*out)->db = db;