rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -7,10 +7,10 @@
7
7
  #ifndef INCLUDE_git_version_h__
8
8
  #define INCLUDE_git_version_h__
9
9
 
10
- #define LIBGIT2_VERSION "0.21.4"
10
+ #define LIBGIT2_VERSION "0.21.0"
11
11
  #define LIBGIT2_VER_MAJOR 0
12
12
  #define LIBGIT2_VER_MINOR 21
13
- #define LIBGIT2_VER_REVISION 4
13
+ #define LIBGIT2_VER_REVISION 0
14
14
 
15
15
  #define LIBGIT2_SOVERSION 21
16
16
 
@@ -0,0 +1,121 @@
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 "annotated_commit.h"
10
+
11
+ #include "git2/commit.h"
12
+ #include "git2/refs.h"
13
+ #include "git2/repository.h"
14
+ #include "git2/annotated_commit.h"
15
+
16
+ static int annotated_commit_init(
17
+ git_annotated_commit **out,
18
+ git_repository *repo,
19
+ const git_oid *id,
20
+ const char *ref_name,
21
+ const char *remote_url)
22
+ {
23
+ git_annotated_commit *annotated_commit;
24
+ int error = 0;
25
+
26
+ assert(out && id);
27
+
28
+ *out = NULL;
29
+
30
+ annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
31
+ GITERR_CHECK_ALLOC(annotated_commit);
32
+
33
+ if (ref_name) {
34
+ annotated_commit->ref_name = git__strdup(ref_name);
35
+ GITERR_CHECK_ALLOC(annotated_commit->ref_name);
36
+ }
37
+
38
+ if (remote_url) {
39
+ annotated_commit->remote_url = git__strdup(remote_url);
40
+ GITERR_CHECK_ALLOC(annotated_commit->remote_url);
41
+ }
42
+
43
+ git_oid_fmt(annotated_commit->id_str, id);
44
+ annotated_commit->id_str[GIT_OID_HEXSZ] = '\0';
45
+
46
+ if ((error = git_commit_lookup(&annotated_commit->commit, repo, id)) < 0) {
47
+ git_annotated_commit_free(annotated_commit);
48
+ return error;
49
+ }
50
+
51
+ *out = annotated_commit;
52
+ return error;
53
+ }
54
+
55
+ int git_annotated_commit_from_ref(
56
+ git_annotated_commit **out,
57
+ git_repository *repo,
58
+ const git_reference *ref)
59
+ {
60
+ git_reference *resolved;
61
+ int error = 0;
62
+
63
+ assert(out && repo && ref);
64
+
65
+ *out = NULL;
66
+
67
+ if ((error = git_reference_resolve(&resolved, ref)) < 0)
68
+ return error;
69
+
70
+ error = annotated_commit_init(out, repo, git_reference_target(resolved),
71
+ git_reference_name(ref), NULL);
72
+
73
+ git_reference_free(resolved);
74
+ return error;
75
+ }
76
+
77
+ int git_annotated_commit_lookup(
78
+ git_annotated_commit **out,
79
+ git_repository *repo,
80
+ const git_oid *id)
81
+ {
82
+ assert(out && repo && id);
83
+
84
+ return annotated_commit_init(out, repo, id, NULL, NULL);
85
+ }
86
+
87
+ int git_annotated_commit_from_fetchhead(
88
+ git_annotated_commit **out,
89
+ git_repository *repo,
90
+ const char *branch_name,
91
+ const char *remote_url,
92
+ const git_oid *id)
93
+ {
94
+ assert(repo && id && branch_name && remote_url);
95
+
96
+ return annotated_commit_init(out, repo, id, branch_name, remote_url);
97
+ }
98
+
99
+ const git_oid *git_annotated_commit_id(
100
+ const git_annotated_commit *annotated_commit)
101
+ {
102
+ assert(annotated_commit);
103
+ return git_commit_id(annotated_commit->commit);
104
+ }
105
+
106
+ void git_annotated_commit_free(git_annotated_commit *annotated_commit)
107
+ {
108
+ if (annotated_commit == NULL)
109
+ return;
110
+
111
+ if (annotated_commit->commit != NULL)
112
+ git_commit_free(annotated_commit->commit);
113
+
114
+ if (annotated_commit->ref_name != NULL)
115
+ git__free(annotated_commit->ref_name);
116
+
117
+ if (annotated_commit->remote_url != NULL)
118
+ git__free(annotated_commit->remote_url);
119
+
120
+ git__free(annotated_commit);
121
+ }
@@ -0,0 +1,22 @@
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_annotated_commit_h__
8
+ #define INCLUDE_annotated_commit_h__
9
+
10
+ #include "git2/oid.h"
11
+
12
+ /** Internal structure for merge inputs */
13
+ struct git_annotated_commit {
14
+ git_commit *commit;
15
+
16
+ char *ref_name;
17
+ char *remote_url;
18
+
19
+ char id_str[GIT_OID_HEXSZ+1];
20
+ };
21
+
22
+ #endif
@@ -377,7 +377,7 @@ static int push_attr_file(
377
377
  return error;
378
378
  }
379
379
 
380
- static int push_one_attr(void *ref, git_buf *path)
380
+ static int push_one_attr(void *ref, const char *path)
381
381
  {
382
382
  int error = 0, n_src, i;
383
383
  attr_walk_up_info *info = (attr_walk_up_info *)ref;
@@ -388,7 +388,7 @@ static int push_one_attr(void *ref, git_buf *path)
388
388
 
389
389
  for (i = 0; !error && i < n_src; ++i)
390
390
  error = push_attr_file(
391
- info->repo, info->files, src[i], path->ptr, GIT_ATTR_FILE);
391
+ info->repo, info->files, src[i], path, GIT_ATTR_FILE);
392
392
 
393
393
  return error;
394
394
  }
@@ -411,7 +411,7 @@ static int collect_attr_files(
411
411
  const char *path,
412
412
  git_vector *files)
413
413
  {
414
- int error;
414
+ int error = 0;
415
415
  git_buf dir = GIT_BUF_INIT;
416
416
  const char *workdir = git_repository_workdir(repo);
417
417
  attr_walk_up_info info = { NULL };
@@ -447,7 +447,11 @@ static int collect_attr_files(
447
447
  giterr_clear(); /* no error even if there is no index */
448
448
  info.files = files;
449
449
 
450
- error = git_path_walk_up(&dir, workdir, push_one_attr, &info);
450
+ if (!strcmp(dir.ptr, "."))
451
+ error = push_one_attr(&info, "");
452
+ else
453
+ error = git_path_walk_up(&dir, workdir, push_one_attr, &info);
454
+
451
455
  if (error < 0)
452
456
  goto cleanup;
453
457
 
@@ -393,6 +393,18 @@ bool git_attr_fnmatch__match(
393
393
  return (matchval != FNM_NOMATCH);
394
394
  }
395
395
 
396
+ /* if path is a directory prefix of a negated pattern, then match */
397
+ if ((match->flags & GIT_ATTR_FNMATCH_NEGATIVE) && path->is_dir) {
398
+ size_t pathlen = strlen(path->path);
399
+ bool prefixed = (pathlen <= match->length) &&
400
+ ((match->flags & GIT_ATTR_FNMATCH_ICASE) ?
401
+ !strncasecmp(match->pattern, path->path, pathlen) :
402
+ !strncmp(match->pattern, path->path, pathlen));
403
+
404
+ if (prefixed && git_path_at_end_of_segment(&match->pattern[pathlen]))
405
+ return true;
406
+ }
407
+
396
408
  return (p_fnmatch(match->pattern, filename, flags) != FNM_NOMATCH);
397
409
  }
398
410
 
@@ -537,7 +549,8 @@ int git_attr_fnmatch__parse(
537
549
  }
538
550
 
539
551
  if (*pattern == '!' && (spec->flags & GIT_ATTR_FNMATCH_ALLOWNEG) != 0) {
540
- spec->flags = spec->flags | GIT_ATTR_FNMATCH_NEGATIVE;
552
+ spec->flags = spec->flags |
553
+ GIT_ATTR_FNMATCH_NEGATIVE | GIT_ATTR_FNMATCH_LEADINGDIR;
541
554
  pattern++;
542
555
  }
543
556
 
@@ -545,7 +558,7 @@ int git_attr_fnmatch__parse(
545
558
  for (scan = pattern; *scan != '\0'; ++scan) {
546
559
  /* scan until (non-escaped) white space */
547
560
  if (git__isspace(*scan) && *(scan - 1) != '\\') {
548
- if (!allow_space || (*scan != ' ' && *scan != '\t'))
561
+ if (!allow_space || (*scan != ' ' && *scan != '\t' && *scan != '\r'))
549
562
  break;
550
563
  }
551
564
 
@@ -566,6 +579,15 @@ int git_attr_fnmatch__parse(
566
579
  if ((spec->length = scan - pattern) == 0)
567
580
  return GIT_ENOTFOUND;
568
581
 
582
+ /*
583
+ * Remove one trailing \r in case this is a CRLF delimited
584
+ * file, in the case of Icon\r\r\n, we still leave the first
585
+ * \r there to match against.
586
+ */
587
+ if (pattern[spec->length - 1] == '\r')
588
+ if (--spec->length == 0)
589
+ return GIT_ENOTFOUND;
590
+
569
591
  if (pattern[spec->length - 1] == '/') {
570
592
  spec->length--;
571
593
  spec->flags = spec->flags | GIT_ATTR_FNMATCH_DIRECTORY;
@@ -316,7 +316,6 @@ static int blame_internal(git_blame *blame)
316
316
  ent->suspect = o;
317
317
 
318
318
  blame->ent = ent;
319
- blame->path = blame->path;
320
319
 
321
320
  git_blame__like_git(blame, blame->options.flags);
322
321
 
@@ -360,7 +360,7 @@ int git_branch_upstream_name(
360
360
  }
361
361
 
362
362
  if (strcmp(".", remote_name) != 0) {
363
- if ((error = git_remote_load(&remote, repo, remote_name)) < 0)
363
+ if ((error = git_remote_lookup(&remote, repo, remote_name)) < 0)
364
364
  goto cleanup;
365
365
 
366
366
  refspec = git_remote__matching_refspec(remote, merge_name);
@@ -384,6 +384,35 @@ cleanup:
384
384
  return error;
385
385
  }
386
386
 
387
+ int git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname)
388
+ {
389
+ int error;
390
+ const char *str;
391
+ git_config *cfg;
392
+
393
+ if (!git_reference__is_branch(refname))
394
+ return not_a_local_branch(refname);
395
+
396
+ git_buf_sanitize(buf);
397
+ if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
398
+ return error;
399
+
400
+ if ((error = retrieve_upstream_configuration(&str, cfg, refname, "branch.%s.remote")) < 0)
401
+ goto cleanup;
402
+
403
+ if (!*str) {
404
+ giterr_set(GITERR_REFERENCE, "branch '%s' does not have an upstream remote", refname);
405
+ error = GIT_ENOTFOUND;
406
+ goto cleanup;
407
+ }
408
+
409
+ error = git_buf_puts(buf, str);
410
+
411
+ cleanup:
412
+ git_config_free(cfg);
413
+ return error;
414
+ }
415
+
387
416
  int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
388
417
  {
389
418
  git_strarray remote_list = {0};
@@ -411,7 +440,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
411
440
 
412
441
  /* Find matching remotes */
413
442
  for (i = 0; i < remote_list.count; i++) {
414
- if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0)
443
+ if ((error = git_remote_lookup(&remote, repo, remote_list.strings[i])) < 0)
415
444
  continue;
416
445
 
417
446
  fetchspec = git_remote__matching_dst_refspec(remote, refname);
@@ -556,7 +585,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
556
585
  goto on_error;
557
586
  } else {
558
587
  /* Get the remoe-tracking branch's refname in its repo */
559
- if (git_remote_load(&remote, repo, git_buf_cstr(&value)) < 0)
588
+ if (git_remote_lookup(&remote, repo, git_buf_cstr(&value)) < 0)
560
589
  goto on_error;
561
590
 
562
591
  fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
@@ -123,9 +123,13 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
123
123
 
124
124
  for (; next; scan = next + 1, next = memchr(scan, '\n', end - scan)) {
125
125
  size_t copylen = next - scan;
126
- /* don't convert existing \r\n to \r\r\n */
127
- size_t extralen = (next > start && next[-1] == '\r') ? 1 : 2;
128
- size_t needsize = tgt->size + copylen + extralen + 1;
126
+ size_t needsize = tgt->size + copylen + 2 + 1;
127
+
128
+ /* if we find mixed line endings, bail */
129
+ if (next > start && next[-1] == '\r') {
130
+ git_buf_free(tgt);
131
+ return GIT_PASSTHROUGH;
132
+ }
129
133
 
130
134
  if (tgt->asize < needsize && git_buf_grow(tgt, needsize) < 0)
131
135
  return -1;
@@ -134,8 +138,8 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
134
138
  memcpy(tgt->ptr + tgt->size, scan, copylen);
135
139
  tgt->size += copylen;
136
140
  }
137
- if (extralen == 2)
138
- tgt->ptr[tgt->size++] = '\r';
141
+
142
+ tgt->ptr[tgt->size++] = '\r';
139
143
  tgt->ptr[tgt->size++] = '\n';
140
144
  }
141
145
 
@@ -56,9 +56,10 @@ GIT_INLINE(int) git_buf_text_puts_escape_regex(git_buf *buf, const char *string)
56
56
  extern void git_buf_text_unescape(git_buf *buf);
57
57
 
58
58
  /**
59
- * Replace all \r\n with \n. Does not modify \r without trailing \n.
59
+ * Replace all \r\n with \n.
60
60
  *
61
- * @return 0 on success, -1 on memory error
61
+ * @return 0 on success, -1 on memory error, GIT_PASSTHROUGH if the
62
+ * source buffer has mixed line endings.
62
63
  */
63
64
  extern int git_buf_text_crlf_to_lf(git_buf *tgt, const git_buf *src);
64
65
 
@@ -7,6 +7,7 @@
7
7
  #include "buffer.h"
8
8
  #include "posix.h"
9
9
  #include "git2/buffer.h"
10
+ #include "buf_text.h"
10
11
  #include <ctype.h>
11
12
 
12
13
  /* Used as default value for git_buf->ptr so that people can always
@@ -141,6 +142,16 @@ int git_buf_set(git_buf *buf, const void *data, size_t len)
141
142
  return 0;
142
143
  }
143
144
 
145
+ int git_buf_is_binary(const git_buf *buf)
146
+ {
147
+ return git_buf_text_is_binary(buf);
148
+ }
149
+
150
+ int git_buf_contains_nul(const git_buf *buf)
151
+ {
152
+ return git_buf_text_contains_nul(buf);
153
+ }
154
+
144
155
  int git_buf_sets(git_buf *buf, const char *string)
145
156
  {
146
157
  return git_buf_set(buf, string, string ? strlen(string) : 0);
@@ -178,10 +189,10 @@ int git_buf_puts(git_buf *buf, const char *string)
178
189
  return git_buf_put(buf, string, strlen(string));
179
190
  }
180
191
 
181
- static const char b64str[] =
192
+ static const char base64_encode[] =
182
193
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
183
194
 
184
- int git_buf_put_base64(git_buf *buf, const char *data, size_t len)
195
+ int git_buf_encode_base64(git_buf *buf, const char *data, size_t len)
185
196
  {
186
197
  size_t extra = len % 3;
187
198
  uint8_t *write, a, b, c;
@@ -196,19 +207,19 @@ int git_buf_put_base64(git_buf *buf, const char *data, size_t len)
196
207
  b = *read++;
197
208
  c = *read++;
198
209
 
199
- *write++ = b64str[a >> 2];
200
- *write++ = b64str[(a & 0x03) << 4 | b >> 4];
201
- *write++ = b64str[(b & 0x0f) << 2 | c >> 6];
202
- *write++ = b64str[c & 0x3f];
210
+ *write++ = base64_encode[a >> 2];
211
+ *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
212
+ *write++ = base64_encode[(b & 0x0f) << 2 | c >> 6];
213
+ *write++ = base64_encode[c & 0x3f];
203
214
  }
204
215
 
205
216
  if (extra > 0) {
206
217
  a = *read++;
207
218
  b = (extra > 1) ? *read++ : 0;
208
219
 
209
- *write++ = b64str[a >> 2];
210
- *write++ = b64str[(a & 0x03) << 4 | b >> 4];
211
- *write++ = (extra > 1) ? b64str[(b & 0x0f) << 2] : '=';
220
+ *write++ = base64_encode[a >> 2];
221
+ *write++ = base64_encode[(a & 0x03) << 4 | b >> 4];
222
+ *write++ = (extra > 1) ? base64_encode[(b & 0x0f) << 2] : '=';
212
223
  *write++ = '=';
213
224
  }
214
225
 
@@ -218,10 +229,56 @@ int git_buf_put_base64(git_buf *buf, const char *data, size_t len)
218
229
  return 0;
219
230
  }
220
231
 
232
+ /* The inverse of base64_encode, offset by '+' == 43. */
233
+ static const int8_t base64_decode[] = {
234
+ 62,
235
+ -1, -1, -1,
236
+ 63,
237
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
238
+ -1, -1, -1, 0, -1, -1, -1,
239
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
240
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
241
+ -1, -1, -1, -1, -1, -1,
242
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
243
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
244
+ };
245
+
246
+ #define BASE64_DECODE_VALUE(c) (((c) < 43 || (c) > 122) ? -1 : base64_decode[c - 43])
247
+
248
+ int git_buf_decode_base64(git_buf *buf, const char *base64, size_t len)
249
+ {
250
+ size_t i;
251
+ int8_t a, b, c, d;
252
+ size_t orig_size = buf->size;
253
+
254
+ assert(len % 4 == 0);
255
+ ENSURE_SIZE(buf, buf->size + (len / 4 * 3) + 1);
256
+
257
+ for (i = 0; i < len; i += 4) {
258
+ if ((a = BASE64_DECODE_VALUE(base64[i])) < 0 ||
259
+ (b = BASE64_DECODE_VALUE(base64[i+1])) < 0 ||
260
+ (c = BASE64_DECODE_VALUE(base64[i+2])) < 0 ||
261
+ (d = BASE64_DECODE_VALUE(base64[i+3])) < 0) {
262
+ buf->size = orig_size;
263
+ buf->ptr[buf->size] = '\0';
264
+
265
+ giterr_set(GITERR_INVALID, "Invalid base64 input");
266
+ return -1;
267
+ }
268
+
269
+ buf->ptr[buf->size++] = ((a << 2) | (b & 0x30) >> 4);
270
+ buf->ptr[buf->size++] = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
271
+ buf->ptr[buf->size++] = (c & 0x03) << 6 | (d & 0x3f);
272
+ }
273
+
274
+ buf->ptr[buf->size] = '\0';
275
+ return 0;
276
+ }
277
+
221
278
  static const char b85str[] =
222
279
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
223
280
 
224
- int git_buf_put_base85(git_buf *buf, const char *data, size_t len)
281
+ int git_buf_encode_base85(git_buf *buf, const char *data, size_t len)
225
282
  {
226
283
  ENSURE_SIZE(buf, buf->size + (5 * ((len / 4) + !!(len % 4))) + 1);
227
284