rugged 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_commit.c +1 -1
  3. data/lib/rugged/commit.rb +16 -2
  4. data/lib/rugged/version.rb +1 -1
  5. data/vendor/libgit2/CMakeLists.txt +31 -69
  6. data/vendor/libgit2/cmake/{Modules/AddCFlagIfSupported.cmake → AddCFlagIfSupported.cmake} +0 -0
  7. data/vendor/libgit2/cmake/{Modules/EnableWarnings.cmake → EnableWarnings.cmake} +0 -0
  8. data/vendor/libgit2/cmake/{Modules/FindCoreFoundation.cmake → FindCoreFoundation.cmake} +0 -0
  9. data/vendor/libgit2/cmake/{Modules/FindGSSAPI.cmake → FindGSSAPI.cmake} +0 -0
  10. data/vendor/libgit2/cmake/{Modules/FindGSSFramework.cmake → FindGSSFramework.cmake} +0 -0
  11. data/vendor/libgit2/cmake/{Modules/FindHTTP_Parser.cmake → FindHTTP_Parser.cmake} +0 -0
  12. data/vendor/libgit2/cmake/{Modules/FindIconv.cmake → FindIconv.cmake} +0 -0
  13. data/vendor/libgit2/cmake/{Modules/FindPCRE.cmake → FindPCRE.cmake} +0 -0
  14. data/vendor/libgit2/cmake/{Modules/FindPCRE2.cmake → FindPCRE2.cmake} +0 -0
  15. data/vendor/libgit2/cmake/{Modules/FindPkgLibraries.cmake → FindPkgLibraries.cmake} +0 -0
  16. data/vendor/libgit2/cmake/{Modules/FindSecurity.cmake → FindSecurity.cmake} +0 -0
  17. data/vendor/libgit2/cmake/{Modules/FindStatNsec.cmake → FindStatNsec.cmake} +0 -0
  18. data/vendor/libgit2/cmake/{Modules/FindmbedTLS.cmake → FindmbedTLS.cmake} +0 -0
  19. data/vendor/libgit2/cmake/{Modules/IdeSplitSources.cmake → IdeSplitSources.cmake} +0 -0
  20. data/vendor/libgit2/cmake/{Modules/PkgBuildConfig.cmake → PkgBuildConfig.cmake} +0 -0
  21. data/vendor/libgit2/cmake/{Modules/SanitizeBool.cmake → SanitizeBool.cmake} +0 -0
  22. data/vendor/libgit2/cmake/{Modules/SelectGSSAPI.cmake → SelectGSSAPI.cmake} +18 -26
  23. data/vendor/libgit2/cmake/{Modules/SelectHTTPSBackend.cmake → SelectHTTPSBackend.cmake} +25 -32
  24. data/vendor/libgit2/cmake/{Modules/SelectHashes.cmake → SelectHashes.cmake} +20 -28
  25. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +4 -3
  26. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +6 -5
  27. data/vendor/libgit2/deps/ntlmclient/compat.h +8 -1
  28. data/vendor/libgit2/deps/ntlmclient/ntlm.c +8 -11
  29. data/vendor/libgit2/deps/pcre/LICENCE +93 -0
  30. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  31. data/vendor/libgit2/deps/pcre/pcre_compile.c +29 -17
  32. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +4 -4
  33. data/vendor/libgit2/deps/pcre/pcreposix.c +2 -3
  34. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -5
  35. data/vendor/libgit2/deps/zlib/deflate.c +1 -0
  36. data/vendor/libgit2/include/git2/annotated_commit.h +1 -1
  37. data/vendor/libgit2/include/git2/blame.h +2 -0
  38. data/vendor/libgit2/include/git2/common.h +15 -3
  39. data/vendor/libgit2/include/git2/deprecated.h +42 -2
  40. data/vendor/libgit2/include/git2/errors.h +2 -1
  41. data/vendor/libgit2/include/git2/index.h +1 -2
  42. data/vendor/libgit2/include/git2/pack.h +1 -1
  43. data/vendor/libgit2/include/git2/strarray.h +6 -10
  44. data/vendor/libgit2/include/git2/version.h +4 -4
  45. data/vendor/libgit2/src/CMakeLists.txt +53 -41
  46. data/vendor/libgit2/src/apply.c +5 -1
  47. data/vendor/libgit2/src/assert_safe.h +58 -0
  48. data/vendor/libgit2/src/attr_file.c +8 -3
  49. data/vendor/libgit2/src/attrcache.c +2 -3
  50. data/vendor/libgit2/src/blame.c +2 -0
  51. data/vendor/libgit2/src/blame_git.c +6 -3
  52. data/vendor/libgit2/src/blob.c +2 -0
  53. data/vendor/libgit2/src/branch.c +19 -21
  54. data/vendor/libgit2/src/buffer.c +6 -3
  55. data/vendor/libgit2/src/cache.c +1 -22
  56. data/vendor/libgit2/src/checkout.c +49 -72
  57. data/vendor/libgit2/src/cherrypick.c +2 -0
  58. data/vendor/libgit2/src/clone.c +78 -18
  59. data/vendor/libgit2/src/common.h +1 -0
  60. data/vendor/libgit2/src/config.c +3 -7
  61. data/vendor/libgit2/src/config_entries.c +35 -27
  62. data/vendor/libgit2/src/config_parse.c +1 -1
  63. data/vendor/libgit2/src/config_snapshot.c +2 -1
  64. data/vendor/libgit2/src/describe.c +5 -1
  65. data/vendor/libgit2/src/diff.c +12 -11
  66. data/vendor/libgit2/src/diff_file.c +3 -1
  67. data/vendor/libgit2/src/diff_generate.c +10 -11
  68. data/vendor/libgit2/src/diff_parse.c +2 -3
  69. data/vendor/libgit2/src/diff_print.c +63 -60
  70. data/vendor/libgit2/src/diff_stats.c +12 -11
  71. data/vendor/libgit2/src/diff_tform.c +2 -3
  72. data/vendor/libgit2/src/errors.c +2 -0
  73. data/vendor/libgit2/src/fetch.c +2 -0
  74. data/vendor/libgit2/src/filter.c +3 -3
  75. data/vendor/libgit2/src/futils.c +3 -3
  76. data/vendor/libgit2/src/futils.h +3 -3
  77. data/vendor/libgit2/src/global.c +3 -1
  78. data/vendor/libgit2/src/idxmap.c +0 -22
  79. data/vendor/libgit2/src/index.c +12 -7
  80. data/vendor/libgit2/src/indexer.c +10 -4
  81. data/vendor/libgit2/src/iterator.c +4 -4
  82. data/vendor/libgit2/src/merge.c +13 -7
  83. data/vendor/libgit2/src/merge_file.c +4 -6
  84. data/vendor/libgit2/src/midx.c +418 -0
  85. data/vendor/libgit2/src/midx.h +83 -0
  86. data/vendor/libgit2/src/mwindow.c +124 -51
  87. data/vendor/libgit2/src/net.c +6 -1
  88. data/vendor/libgit2/src/object.c +2 -1
  89. data/vendor/libgit2/src/odb.c +9 -6
  90. data/vendor/libgit2/src/odb_loose.c +3 -3
  91. data/vendor/libgit2/src/odb_mempack.c +2 -0
  92. data/vendor/libgit2/src/oid.c +2 -0
  93. data/vendor/libgit2/src/pack-objects.c +29 -21
  94. data/vendor/libgit2/src/pack.c +47 -28
  95. data/vendor/libgit2/src/pack.h +19 -2
  96. data/vendor/libgit2/src/patch_generate.c +1 -3
  97. data/vendor/libgit2/src/patch_parse.c +4 -2
  98. data/vendor/libgit2/src/path.c +4 -4
  99. data/vendor/libgit2/src/pathspec.c +4 -3
  100. data/vendor/libgit2/src/pool.c +21 -15
  101. data/vendor/libgit2/src/pool.h +9 -1
  102. data/vendor/libgit2/src/proxy.c +2 -0
  103. data/vendor/libgit2/src/push.c +2 -0
  104. data/vendor/libgit2/src/rebase.c +2 -0
  105. data/vendor/libgit2/src/refdb.c +135 -0
  106. data/vendor/libgit2/src/refdb.h +69 -0
  107. data/vendor/libgit2/src/refdb_fs.c +19 -81
  108. data/vendor/libgit2/src/reflog.c +2 -6
  109. data/vendor/libgit2/src/refs.c +60 -188
  110. data/vendor/libgit2/src/refs.h +1 -19
  111. data/vendor/libgit2/src/regexp.c +2 -2
  112. data/vendor/libgit2/src/remote.c +32 -17
  113. data/vendor/libgit2/src/repository.c +168 -79
  114. data/vendor/libgit2/src/repository.h +10 -27
  115. data/vendor/libgit2/src/revert.c +2 -0
  116. data/vendor/libgit2/src/revparse.c +5 -4
  117. data/vendor/libgit2/src/revwalk.c +3 -5
  118. data/vendor/libgit2/src/settings.c +9 -0
  119. data/vendor/libgit2/src/sortedcache.c +2 -3
  120. data/vendor/libgit2/src/stash.c +2 -0
  121. data/vendor/libgit2/src/status.c +2 -0
  122. data/vendor/libgit2/src/strarray.c +63 -0
  123. data/vendor/libgit2/src/streams/openssl.c +12 -6
  124. data/vendor/libgit2/src/streams/registry.c +5 -3
  125. data/vendor/libgit2/src/submodule.c +6 -4
  126. data/vendor/libgit2/src/sysdir.c +4 -20
  127. data/vendor/libgit2/src/sysdir.h +0 -11
  128. data/vendor/libgit2/src/tag.c +2 -0
  129. data/vendor/libgit2/src/thread-utils.h +139 -21
  130. data/vendor/libgit2/src/transaction.c +2 -1
  131. data/vendor/libgit2/src/transports/credential.c +2 -0
  132. data/vendor/libgit2/src/transports/credential_helpers.c +2 -0
  133. data/vendor/libgit2/src/transports/httpclient.c +6 -8
  134. data/vendor/libgit2/src/transports/local.c +2 -2
  135. data/vendor/libgit2/src/transports/smart.c +2 -2
  136. data/vendor/libgit2/src/transports/winhttp.c +18 -7
  137. data/vendor/libgit2/src/unix/posix.h +13 -1
  138. data/vendor/libgit2/src/util.c +25 -58
  139. data/vendor/libgit2/src/util.h +2 -2
  140. data/vendor/libgit2/src/win32/git2.rc +18 -3
  141. data/vendor/libgit2/src/win32/path_w32.c +2 -2
  142. data/vendor/libgit2/src/worktree.c +4 -0
  143. metadata +27 -25
  144. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +0 -29
  145. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +0 -96
  146. data/vendor/libgit2/src/refdb_fs.h +0 -19
@@ -81,7 +81,7 @@ typedef struct {
81
81
  * Of course, you can use this in other ways, but those are the
82
82
  * two most common patterns.
83
83
  */
84
- extern void git_pool_init(git_pool *pool, size_t item_size);
84
+ extern int git_pool_init(git_pool *pool, size_t item_size);
85
85
 
86
86
  /**
87
87
  * Free all items in pool
@@ -135,4 +135,12 @@ extern uint32_t git_pool__open_pages(git_pool *pool);
135
135
  #endif
136
136
  extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr);
137
137
 
138
+ /**
139
+ * This function is being called by our global setup routines to
140
+ * initialize the system pool size.
141
+ *
142
+ * @return 0 on success, <0 on failure
143
+ */
144
+ extern int git_pool_global_init(void);
145
+
138
146
  #endif
@@ -16,10 +16,12 @@ int git_proxy_options_init(git_proxy_options *opts, unsigned int version)
16
16
  return 0;
17
17
  }
18
18
 
19
+ #ifndef GIT_DEPRECATE_HARD
19
20
  int git_proxy_init_options(git_proxy_options *opts, unsigned int version)
20
21
  {
21
22
  return git_proxy_options_init(opts, version);
22
23
  }
24
+ #endif
23
25
 
24
26
  int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src)
25
27
  {
@@ -555,7 +555,9 @@ int git_push_options_init(git_push_options *opts, unsigned int version)
555
555
  return 0;
556
556
  }
557
557
 
558
+ #ifndef GIT_DEPRECATE_HARD
558
559
  int git_push_init_options(git_push_options *opts, unsigned int version)
559
560
  {
560
561
  return git_push_options_init(opts, version);
561
562
  }
563
+ #endif
@@ -501,10 +501,12 @@ int git_rebase_options_init(git_rebase_options *opts, unsigned int version)
501
501
  return 0;
502
502
  }
503
503
 
504
+ #ifndef GIT_DEPRECATE_HARD
504
505
  int git_rebase_init_options(git_rebase_options *opts, unsigned int version)
505
506
  {
506
507
  return git_rebase_options_init(opts, version);
507
508
  }
509
+ #endif
508
510
 
509
511
  static int rebase_ensure_not_in_progress(git_repository *repo)
510
512
  {
@@ -17,6 +17,9 @@
17
17
  #include "reflog.h"
18
18
  #include "posix.h"
19
19
 
20
+ #define DEFAULT_NESTING_LEVEL 5
21
+ #define MAX_NESTING_LEVEL 10
22
+
20
23
  int git_refdb_new(git_refdb **out, git_repository *repo)
21
24
  {
22
25
  git_refdb *db;
@@ -134,6 +137,59 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
134
137
  return 0;
135
138
  }
136
139
 
140
+ int git_refdb_resolve(
141
+ git_reference **out,
142
+ git_refdb *db,
143
+ const char *ref_name,
144
+ int max_nesting)
145
+ {
146
+ git_reference *ref = NULL;
147
+ int error = 0, nesting;
148
+
149
+ *out = NULL;
150
+
151
+ if (max_nesting > MAX_NESTING_LEVEL)
152
+ max_nesting = MAX_NESTING_LEVEL;
153
+ else if (max_nesting < 0)
154
+ max_nesting = DEFAULT_NESTING_LEVEL;
155
+
156
+ if ((error = git_refdb_lookup(&ref, db, ref_name)) < 0)
157
+ goto out;
158
+
159
+ for (nesting = 0; nesting < max_nesting; nesting++) {
160
+ git_reference *resolved;
161
+
162
+ if (ref->type == GIT_REFERENCE_DIRECT)
163
+ break;
164
+
165
+ if ((error = git_refdb_lookup(&resolved, db, git_reference_symbolic_target(ref))) < 0) {
166
+ /* If we found a symbolic reference with a nonexistent target, return it. */
167
+ if (error == GIT_ENOTFOUND) {
168
+ error = 0;
169
+ *out = ref;
170
+ ref = NULL;
171
+ }
172
+ goto out;
173
+ }
174
+
175
+ git_reference_free(ref);
176
+ ref = resolved;
177
+ }
178
+
179
+ if (ref->type != GIT_REFERENCE_DIRECT && max_nesting != 0) {
180
+ git_error_set(GIT_ERROR_REFERENCE,
181
+ "cannot resolve reference (>%u levels deep)", max_nesting);
182
+ error = -1;
183
+ goto out;
184
+ }
185
+
186
+ *out = ref;
187
+ ref = NULL;
188
+ out:
189
+ git_reference_free(ref);
190
+ return error;
191
+ }
192
+
137
193
  int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob)
138
194
  {
139
195
  int error;
@@ -231,6 +287,85 @@ int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name)
231
287
  return 0;
232
288
  }
233
289
 
290
+ int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *ref)
291
+ {
292
+ int error, logall;
293
+
294
+ error = git_repository__configmap_lookup(&logall, db->repo, GIT_CONFIGMAP_LOGALLREFUPDATES);
295
+ if (error < 0)
296
+ return error;
297
+
298
+ /* Defaults to the opposite of the repo being bare */
299
+ if (logall == GIT_LOGALLREFUPDATES_UNSET)
300
+ logall = !git_repository_is_bare(db->repo);
301
+
302
+ *out = 0;
303
+ switch (logall) {
304
+ case GIT_LOGALLREFUPDATES_FALSE:
305
+ *out = 0;
306
+ break;
307
+
308
+ case GIT_LOGALLREFUPDATES_TRUE:
309
+ /* Only write if it already has a log,
310
+ * or if it's under heads/, remotes/ or notes/
311
+ */
312
+ *out = git_refdb_has_log(db, ref->name) ||
313
+ !git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) ||
314
+ !git__strcmp(ref->name, GIT_HEAD_FILE) ||
315
+ !git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) ||
316
+ !git__prefixcmp(ref->name, GIT_REFS_NOTES_DIR);
317
+ break;
318
+
319
+ case GIT_LOGALLREFUPDATES_ALWAYS:
320
+ *out = 1;
321
+ break;
322
+ }
323
+
324
+ return 0;
325
+ }
326
+
327
+ int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_reference *ref)
328
+ {
329
+ git_reference *head = NULL, *resolved = NULL;
330
+ const char *name;
331
+ int error;
332
+
333
+ *out = 0;
334
+
335
+ if (ref->type == GIT_REFERENCE_SYMBOLIC) {
336
+ error = 0;
337
+ goto out;
338
+ }
339
+
340
+ if ((error = git_refdb_lookup(&head, db, GIT_HEAD_FILE)) < 0)
341
+ goto out;
342
+
343
+ if (git_reference_type(head) == GIT_REFERENCE_DIRECT)
344
+ goto out;
345
+
346
+ /* Go down the symref chain until we find the branch */
347
+ if ((error = git_refdb_resolve(&resolved, db, git_reference_symbolic_target(head), -1)) < 0) {
348
+ if (error != GIT_ENOTFOUND)
349
+ goto out;
350
+ error = 0;
351
+ name = git_reference_symbolic_target(head);
352
+ } else if (git_reference_type(resolved) == GIT_REFERENCE_SYMBOLIC) {
353
+ name = git_reference_symbolic_target(resolved);
354
+ } else {
355
+ name = git_reference_name(resolved);
356
+ }
357
+
358
+ if (strcmp(name, ref->name))
359
+ goto out;
360
+
361
+ *out = 1;
362
+
363
+ out:
364
+ git_reference_free(resolved);
365
+ git_reference_free(head);
366
+ return error;
367
+ }
368
+
234
369
  int git_refdb_has_log(git_refdb *db, const char *refname)
235
370
  {
236
371
  assert(db && refname);
@@ -30,6 +30,31 @@ int git_refdb_lookup(
30
30
  git_refdb *refdb,
31
31
  const char *ref_name);
32
32
 
33
+ /**
34
+ * Resolve the reference by following symbolic references.
35
+ *
36
+ * Given a reference name, this function will follow any symbolic references up
37
+ * to `max_nesting` deep and return the resolved direct reference. If any of
38
+ * the intermediate symbolic references points to a non-existing reference,
39
+ * then that symbolic reference is returned instead with an error code of `0`.
40
+ * If the given reference is a direct reference already, it is returned
41
+ * directly.
42
+ *
43
+ * If `max_nesting` is `0`, the reference will not be resolved. If it's
44
+ * negative, it will be set to the default resolve depth which is `5`.
45
+ *
46
+ * @param out Pointer to store the result in.
47
+ * @param db The refdb to use for resolving the reference.
48
+ * @param ref_name The reference name to lookup and resolve.
49
+ * @param max_nesting The maximum nesting depth.
50
+ * @return `0` on success, a negative error code otherwise.
51
+ */
52
+ int git_refdb_resolve(
53
+ git_reference **out,
54
+ git_refdb *db,
55
+ const char *ref_name,
56
+ int max_nesting);
57
+
33
58
  int git_refdb_rename(
34
59
  git_reference **out,
35
60
  git_refdb *db,
@@ -50,6 +75,50 @@ int git_refdb_delete(git_refdb *refdb, const char *ref_name, const git_oid *old_
50
75
  int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name);
51
76
  int git_refdb_reflog_write(git_reflog *reflog);
52
77
 
78
+ /**
79
+ * Determine whether a reflog entry should be created for the given reference.
80
+ *
81
+ * Whether or not writing to a reference should create a reflog entry is
82
+ * dependent on a number of things. Most importantly, there's the
83
+ * "core.logAllRefUpdates" setting that controls in which situations a
84
+ * reference should get a corresponding reflog entry. The following values for
85
+ * it are understood:
86
+ *
87
+ * - "false": Do not log reference updates.
88
+ *
89
+ * - "true": Log normal reference updates. This will write entries for
90
+ * references in "refs/heads", "refs/remotes", "refs/notes" and
91
+ * "HEAD" or if the reference already has a log entry.
92
+ *
93
+ * - "always": Always create a reflog entry.
94
+ *
95
+ * If unset, the value will default to "true" for non-bare repositories and
96
+ * "false" for bare ones.
97
+ *
98
+ * @param out pointer to which the result will be written, `1` means a reflog
99
+ * entry should be written, `0` means none should be written.
100
+ * @param db The refdb to decide this for.
101
+ * @param ref The reference one wants to check.
102
+ * @return `0` on success, a negative error code otherwise.
103
+ */
104
+ int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *ref);
105
+
106
+ /**
107
+ * Determine whether a reflog entry should be created for HEAD if creating one
108
+ * for the given reference
109
+ *
110
+ * In case the given reference is being pointed to by HEAD, then creating a
111
+ * reflog entry for this reference also requires us to create a corresponding
112
+ * reflog entry for HEAD. This function can be used to determine that scenario.
113
+ *
114
+ * @param out pointer to which the result will be written, `1` means a reflog
115
+ * entry should be written, `0` means none should be written.
116
+ * @param db The refdb to decide this for.
117
+ * @param ref The reference one wants to check.
118
+ * @return `0` on success, a negative error code otherwise.
119
+ */
120
+ int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_reference *ref);
121
+
53
122
  int git_refdb_has_log(git_refdb *db, const char *refname);
54
123
  int git_refdb_ensure_log(git_refdb *refdb, const char *refname);
55
124
 
@@ -5,8 +5,6 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
 
8
- #include "refdb_fs.h"
9
-
10
8
  #include "refs.h"
11
9
  #include "hash.h"
12
10
  #include "repository.h"
@@ -685,7 +683,8 @@ static int refdb_fs_backend__iterator(
685
683
  iter = git__calloc(1, sizeof(refdb_fs_iter));
686
684
  GIT_ERROR_CHECK_ALLOC(iter);
687
685
 
688
- git_pool_init(&iter->pool, 1);
686
+ if ((error = git_pool_init(&iter->pool, 1)) < 0)
687
+ goto out;
689
688
 
690
689
  if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
691
690
  goto out;
@@ -1129,44 +1128,6 @@ cleanup:
1129
1128
  }
1130
1129
 
1131
1130
  static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *author, const char *message);
1132
- static int has_reflog(git_repository *repo, const char *name);
1133
-
1134
- static int should_write_reflog(int *write, git_repository *repo, const char *name)
1135
- {
1136
- int error, logall;
1137
-
1138
- error = git_repository__configmap_lookup(&logall, repo, GIT_CONFIGMAP_LOGALLREFUPDATES);
1139
- if (error < 0)
1140
- return error;
1141
-
1142
- /* Defaults to the opposite of the repo being bare */
1143
- if (logall == GIT_LOGALLREFUPDATES_UNSET)
1144
- logall = !git_repository_is_bare(repo);
1145
-
1146
- *write = 0;
1147
- switch (logall) {
1148
- case GIT_LOGALLREFUPDATES_FALSE:
1149
- *write = 0;
1150
- break;
1151
-
1152
- case GIT_LOGALLREFUPDATES_TRUE:
1153
- /* Only write if it already has a log,
1154
- * or if it's under heads/, remotes/ or notes/
1155
- */
1156
- *write = has_reflog(repo, name) ||
1157
- !git__prefixcmp(name, GIT_REFS_HEADS_DIR) ||
1158
- !git__strcmp(name, GIT_HEAD_FILE) ||
1159
- !git__prefixcmp(name, GIT_REFS_REMOTES_DIR) ||
1160
- !git__prefixcmp(name, GIT_REFS_NOTES_DIR);
1161
- break;
1162
-
1163
- case GIT_LOGALLREFUPDATES_ALWAYS:
1164
- *write = 1;
1165
- break;
1166
- }
1167
-
1168
- return 0;
1169
- }
1170
1131
 
1171
1132
  static int cmp_old_ref(int *cmp, git_refdb_backend *backend, const char *name,
1172
1133
  const git_oid *old_id, const char *old_target)
@@ -1220,54 +1181,28 @@ out:
1220
1181
  */
1221
1182
  static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
1222
1183
  {
1223
- int error;
1184
+ git_reference *head = NULL;
1185
+ git_refdb *refdb = NULL;
1186
+ int error, write_reflog;
1224
1187
  git_oid old_id;
1225
- git_reference *tmp = NULL, *head = NULL, *peeled = NULL;
1226
- const char *name;
1227
1188
 
1228
- if (ref->type == GIT_REFERENCE_SYMBOLIC)
1229
- return 0;
1189
+ if ((error = git_repository_refdb(&refdb, backend->repo)) < 0 ||
1190
+ (error = git_refdb_should_write_head_reflog(&write_reflog, refdb, ref)) < 0)
1191
+ goto out;
1192
+ if (!write_reflog)
1193
+ goto out;
1230
1194
 
1231
1195
  /* if we can't resolve, we use {0}*40 as old id */
1232
1196
  if (git_reference_name_to_id(&old_id, backend->repo, ref->name) < 0)
1233
1197
  memset(&old_id, 0, sizeof(old_id));
1234
1198
 
1235
- if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0)
1236
- return error;
1237
-
1238
- if (git_reference_type(head) == GIT_REFERENCE_DIRECT)
1239
- goto cleanup;
1240
-
1241
- if ((error = git_reference_lookup(&tmp, backend->repo, GIT_HEAD_FILE)) < 0)
1242
- goto cleanup;
1243
-
1244
- /* Go down the symref chain until we find the branch */
1245
- while (git_reference_type(tmp) == GIT_REFERENCE_SYMBOLIC) {
1246
- error = git_reference_lookup(&peeled, backend->repo, git_reference_symbolic_target(tmp));
1247
- if (error < 0)
1248
- break;
1249
-
1250
- git_reference_free(tmp);
1251
- tmp = peeled;
1252
- }
1253
-
1254
- if (error == GIT_ENOTFOUND) {
1255
- error = 0;
1256
- name = git_reference_symbolic_target(tmp);
1257
- } else if (error < 0) {
1258
- goto cleanup;
1259
- } else {
1260
- name = git_reference_name(tmp);
1261
- }
1262
-
1263
- if (strcmp(name, ref->name))
1264
- goto cleanup;
1265
-
1266
- error = reflog_append(backend, head, &old_id, git_reference_target(ref), who, message);
1199
+ if ((error = git_reference_lookup(&head, backend->repo, GIT_HEAD_FILE)) < 0 ||
1200
+ (error = reflog_append(backend, head, &old_id, git_reference_target(ref), who, message)) < 0)
1201
+ goto out;
1267
1202
 
1268
- cleanup:
1269
- git_reference_free(tmp);
1203
+ out:
1270
1204
  git_reference_free(head);
1205
+ git_refdb_free(refdb);
1271
1206
  return error;
1272
1207
  }
1273
1208
 
@@ -1336,7 +1271,10 @@ static int refdb_fs_backend__write_tail(
1336
1271
  }
1337
1272
 
1338
1273
  if (update_reflog) {
1339
- if ((error = should_write_reflog(&should_write, backend->repo, ref->name)) < 0)
1274
+ git_refdb *refdb;
1275
+
1276
+ if ((error = git_repository_refdb__weakptr(&refdb, backend->repo)) < 0 ||
1277
+ (error = git_refdb_should_write_reflog(&should_write, refdb, ref)) < 0)
1340
1278
  goto on_error;
1341
1279
 
1342
1280
  if (should_write) {
@@ -12,12 +12,8 @@
12
12
  #include "signature.h"
13
13
  #include "refdb.h"
14
14
 
15
- #include <git2/sys/refdb_backend.h>
16
-
17
- git_reflog_entry *git_reflog_entry__alloc(void)
18
- {
19
- return git__calloc(1, sizeof(git_reflog_entry));
20
- }
15
+ #include "git2/sys/refdb_backend.h"
16
+ #include "git2/sys/reflog.h"
21
17
 
22
18
  void git_reflog_entry__free(git_reflog_entry *entry)
23
19
  {