Commit a57dd3b7a46c9a2f87f203f1ab372fa28e10e571

Carlos Martín Nieto 2013-11-13T18:15:20

reflog: integrate into the ref writing Whenever a reference is created or updated, we need to write to the reflog regardless of whether the user gave us a message, so we shouldn't leave that to the ref frontend, but integrate it into the backend. This also eliminates the race between ref update and writing to the reflog, as we protect the reflog with the ref lock. As an additional benefit, this reflog append on the backend happens by appending to the file instead of parsing and rewriting it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
index d5611d0..131e1b5 100644
--- a/include/git2/sys/refdb_backend.h
+++ b/include/git2/sys/refdb_backend.h
@@ -94,12 +94,12 @@ struct git_refdb_backend {
 	 */
 	int (*write)(git_refdb_backend *backend,
 		     const git_reference *ref, int force,
-		     const char *message);
+		     const git_signature *who, const char *message);
 
 	int (*rename)(
 		git_reference **out, git_refdb_backend *backend,
 		const char *old_name, const char *new_name, int force,
-		const char *message);
+		const git_signature *who, const char *message);
 
 	/**
 	 * Deletes the given reference from the refdb.  A refdb implementation
diff --git a/src/refdb.c b/src/refdb.c
index 8f002eb..bc8c2b3 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -167,14 +167,14 @@ void git_refdb_iterator_free(git_reference_iterator *iter)
 	iter->free(iter);
 }
 
-int git_refdb_write(git_refdb *db, git_reference *ref, int force, const char *message)
+int git_refdb_write(git_refdb *db, git_reference *ref, int force, const git_signature *who, const char *message)
 {
 	assert(db && db->backend);
 
 	GIT_REFCOUNT_INC(db);
 	ref->db = db;
 
-	return db->backend->write(db->backend, ref, force, message);
+	return db->backend->write(db->backend, ref, force, who, message);
 }
 
 int git_refdb_rename(
@@ -183,12 +183,13 @@ int git_refdb_rename(
 	const char *old_name,
 	const char *new_name,
 	int force,
+	const git_signature *who,
 	const char *message)
 {
 	int error;
 
 	assert(db && db->backend);
-	error = db->backend->rename(out, db->backend, old_name, new_name, force, message);
+	error = db->backend->rename(out, db->backend, old_name, new_name, force, who, message);
 	if (error < 0)
 		return error;
 
diff --git a/src/refdb.h b/src/refdb.h
index 4dea20b..215ae17 100644
--- a/src/refdb.h
+++ b/src/refdb.h
@@ -34,6 +34,7 @@ int git_refdb_rename(
 	const char *old_name,
 	const char *new_name,
 	int force,
+	const git_signature *who,
 	const char *message);
 
 int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob);
@@ -41,7 +42,7 @@ int git_refdb_iterator_next(git_reference **out, git_reference_iterator *iter);
 int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter);
 void git_refdb_iterator_free(git_reference_iterator *iter);
 
-int git_refdb_write(git_refdb *refdb, git_reference *ref, int force, const char *message);
+int git_refdb_write(git_refdb *refdb, git_reference *ref, int force, const git_signature *who, const char *message);
 int git_refdb_delete(git_refdb *refdb, const char *ref_name);
 
 int git_refdb_reflog_read(git_reflog **out, git_refdb *db,  const char *name);
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 6eb6ec4..2f7b434 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -688,9 +688,8 @@ static int reference_path_available(
 	return 0;
 }
 
-static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
+static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const git_reference *ref)
 {
-	git_filebuf file = GIT_FILEBUF_INIT;
 	git_buf ref_path = GIT_BUF_INIT;
 
 	/* Remove a possibly existing empty directory hierarchy
@@ -702,25 +701,29 @@ static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
 	if (git_buf_joinpath(&ref_path, backend->path, ref->name) < 0)
 		return -1;
 
-	if (git_filebuf_open(&file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) {
+	if (git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) {
 		git_buf_free(&ref_path);
 		return -1;
 	}
 
 	git_buf_free(&ref_path);
+	return 0;
+}
 
+static int loose_commit(git_filebuf *file, const git_reference *ref)
+{
 	if (ref->type == GIT_REF_OID) {
 		char oid[GIT_OID_HEXSZ + 1];
 		git_oid_nfmt(oid, sizeof(oid), &ref->target.oid);
 
-		git_filebuf_printf(&file, "%s\n", oid);
+		git_filebuf_printf(file, "%s\n", oid);
 	} else if (ref->type == GIT_REF_SYMBOLIC) {
-		git_filebuf_printf(&file, GIT_SYMREF "%s\n", ref->target.symbolic);
+		git_filebuf_printf(file, GIT_SYMREF "%s\n", ref->target.symbolic);
 	} else {
 		assert(0); /* don't let this happen */
 	}
 
-	return git_filebuf_commit(&file);
+	return git_filebuf_commit(file);
 }
 
 /*
@@ -907,13 +910,17 @@ fail:
 	return -1;
 }
 
+static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_signature *author, const char *message);
+
 static int refdb_fs_backend__write(
 	git_refdb_backend *_backend,
 	const git_reference *ref,
 	int force,
+	const git_signature *who,
 	const char *message)
 {
 	refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
+	git_filebuf file = GIT_FILEBUF_INIT;
 	int error;
 
 	assert(backend);
@@ -922,7 +929,16 @@ static int refdb_fs_backend__write(
 	if (error < 0)
 		return error;
 
-	return loose_write(backend, ref);
+	/* We need to perform the reflog append under the ref's lock */
+	if ((error = loose_lock(&file, backend, ref)) < 0)
+		return error;
+
+	if ((error = reflog_append(backend, ref, who, message)) < 0) {
+		git_filebuf_cleanup(&file);
+		return error;
+	}
+
+	return loose_commit(&file, ref);
 }
 
 static int refdb_fs_backend__delete(
@@ -970,16 +986,20 @@ static int refdb_fs_backend__delete(
 	return packed_write(backend);
 }
 
+static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name);
+
 static int refdb_fs_backend__rename(
 	git_reference **out,
 	git_refdb_backend *_backend,
 	const char *old_name,
 	const char *new_name,
 	int force,
+	const git_signature *who,
 	const char *message)
 {
 	refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
 	git_reference *old, *new;
+	git_filebuf file = GIT_FILEBUF_INIT;
 	int error;
 
 	assert(backend);
@@ -1000,7 +1020,28 @@ static int refdb_fs_backend__rename(
 		return -1;
 	}
 
-	if ((error = loose_write(backend, new)) < 0 || out == NULL) {
+	if ((error = loose_lock(&file, backend, new)) < 0) {
+		git_reference_free(new);
+		return error;
+	}
+
+	/* Try to rename the refog; it's ok if the old doesn't exist */
+	error = refdb_reflog_fs__rename(_backend, old_name, new_name);
+	if (((error == 0) || (error == GIT_ENOTFOUND)) &&
+	    ((error = reflog_append(backend, new, who, message)) < 0)) {
+		git_reference_free(new);
+		git_filebuf_cleanup(&file);
+		return error;
+	}
+
+	if (error < 0) {
+		git_reference_free(new);
+		git_filebuf_cleanup(&file);
+		return error;
+	}
+
+
+	if ((error = loose_commit(&file, new)) < 0 || out == NULL) {
 		git_reference_free(new);
 		return error;
 	}
@@ -1330,6 +1371,48 @@ success:
 	return error;
 }
 
+/* Append to the reflog, must be called under reference lock */
+static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_signature *who, const char *message)
+{
+	int error;
+	git_oid old_id, new_id;
+	git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
+	git_repository *repo = backend->repo;
+
+	/* Creation of symbolic references doesn't get a reflog entry */
+	if (ref->type == GIT_REF_SYMBOLIC)
+		return 0;
+
+	error = git_reference_name_to_id(&old_id, repo, ref->name);
+	if (error == GIT_ENOTFOUND) {
+		memset(&old_id, 0, sizeof(git_oid));
+		error = 0;
+	}
+	if (error < 0)
+		return error;
+
+	git_oid_cpy(&new_id, git_reference_target(ref));
+
+	if ((error = serialize_reflog_entry(&buf, &old_id, &new_id, who, message)) < 0)
+		goto cleanup;
+
+	if ((error = retrieve_reflog_path(&path, repo, ref->name)) < 0)
+		goto cleanup;
+
+	if (((error = git_futils_mkpath2file(git_buf_cstr(&path), 0777)) < 0) &&
+	    (error != GIT_EEXISTS)) {
+		goto cleanup;
+	}
+
+	error = git_futils_writebuffer(&buf, git_buf_cstr(&path), O_WRONLY|O_CREAT|O_APPEND, GIT_REFLOG_FILE_MODE);
+
+cleanup:
+	git_buf_free(&buf);
+	git_buf_free(&path);
+
+	return error;
+}
+
 static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
 {
 	int error = 0, fd;
@@ -1358,6 +1441,11 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
 	if (git_buf_joinpath(&new_path, git_buf_cstr(&temp_path), git_buf_cstr(&normalized)) < 0)
 		return -1;
 
+	if (!git_path_exists(git_buf_cstr(&old_path))) {
+		error = GIT_ENOTFOUND;
+		goto cleanup;
+	}
+
 	/*
 	 * Move the reflog to a temporary place. This two-phase renaming is required
 	 * in order to cope with funny renaming use cases when one tries to move a reference
diff --git a/src/refs.c b/src/refs.c
index dbbdda0..598d687 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -21,6 +21,7 @@
 #include <git2/refs.h>
 #include <git2/refdb.h>
 #include <git2/sys/refs.h>
+#include <git2/signature.h>
 
 GIT__USE_STRMAP;
 
@@ -322,23 +323,6 @@ const char *git_reference_symbolic_target(const git_reference *ref)
 	return ref->target.symbolic;
 }
 
-static int feed_reflog(
-	const git_reference *ref,
-	const git_signature *signature,
-	const char *log_message)
-{
-
-	git_oid peeled_ref_oid;
-	int error;
-
-	if ((error = git_reference_name_to_id(&peeled_ref_oid,
-		git_reference_owner(ref), git_reference_name(ref))) < 0)
-		return error;
-
-	return git_reflog_append_to(git_reference_owner(ref), git_reference_name(ref),
-				    &peeled_ref_oid, signature, log_message);
-}
-
 static int reference__create(
 	git_reference **ref_out,
 	git_repository *repo,
@@ -355,7 +339,7 @@ static int reference__create(
 	int error = 0;
 
 	assert(repo && name);
-	assert(!((signature == NULL) ^ (log_message == NULL)));
+	assert(symbolic || signature);
 
 	if (ref_out)
 		*ref_out = NULL;
@@ -396,12 +380,7 @@ static int reference__create(
 
 	GITERR_CHECK_ALLOC(ref);
 
-	if ((error = git_refdb_write(refdb, ref, force, log_message)) < 0) {
-		git_reference_free(ref);
-		return error;
-	}
-
-	if (log_message && (error = feed_reflog(ref, signature, log_message)) < 0) {
+	if ((error = git_refdb_write(refdb, ref, force, signature, log_message)) < 0) {
 		git_reference_free(ref);
 		return error;
 	}
@@ -421,9 +400,22 @@ int git_reference_create(
 	const git_oid *oid,
 	int force)
 {
+	git_signature *who;
+	int error;
+
 	assert(oid);
 
-	return reference__create(ref_out, repo, name, oid, NULL, force, NULL, NULL);
+	/* Should we return an error if there is no default? */
+	if (((error = git_signature_default(&who, repo)) < 0) &&
+	    ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
+		return error;
+	}
+
+	error = reference__create(ref_out, repo, name, oid, NULL, force, who, NULL);
+
+	git_signature_free(who);
+
+	return error;
 }
 
 int git_reference_create_with_log(
@@ -449,25 +441,9 @@ int git_reference_symbolic_create(
 	int force)
 {
 	assert(target);
-
 	return reference__create(ref_out, repo, name, NULL, target, force, NULL, NULL);
 }
 
-int git_reference_symbolic_create_with_log(
-	git_reference **ref_out,
-	git_repository *repo,
-	const char *name,
-	const char *target,
-	int force,
-	const git_signature *signature,
-	const char* log_message)
-{
-	assert(target && signature && log_message);
-
-	return reference__create(
-		ref_out, repo, name, NULL, target, force, signature, log_message);
-}
-
 static int ensure_is_an_updatable_direct_reference(git_reference *ref)
 {
 	if (ref->type == GIT_REF_OID)
@@ -535,36 +511,15 @@ int git_reference_symbolic_set_target(
 	return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1);
 }
 
-int git_reference_symbolic_set_target_with_log(
-	git_reference **out,
-	git_reference *ref,
-	const char *target,
-	const git_signature *signature,
-	const char *log_message)
-{
-	int error;
-
-	assert(out && ref && target);
-	assert(signature && log_message);
-
-	if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0)
-		return error;
-
-	return git_reference_symbolic_create_with_log(
-		out, ref->db->repo, ref->name, target, 1, signature, log_message);
-}
-
-int git_reference_rename(
-	git_reference **out,
-	git_reference *ref,
-	const char *new_name,
-	int force)
+static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
+				 const git_signature *signature, const char *message)
 {
 	unsigned int normalization_flags;
 	char normalized[GIT_REFNAME_MAX];
 	bool should_head_be_updated = false;
 	int error = 0;
-	int reference_has_log;
+
+	assert(ref && new_name && signature);
 
 	normalization_flags = ref->type == GIT_REF_SYMBOLIC ?
 		GIT_REF_FORMAT_ALLOW_ONELEVEL : GIT_REF_FORMAT_NORMAL;
@@ -573,13 +528,14 @@ int git_reference_rename(
 			normalized, sizeof(normalized), new_name, normalization_flags)) < 0)
 		return error;
 
+
 	/* Check if we have to update HEAD. */
 	if ((error = git_branch_is_head(ref)) < 0)
 		return error;
 
 	should_head_be_updated = (error > 0);
 
-	if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force, NULL)) < 0)
+	if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force, signature, message)) < 0)
 		return error;
 
 	/* Update HEAD it was poiting to the reference being renamed. */
@@ -589,15 +545,41 @@ int git_reference_rename(
 		return error;
 	}
 
-	/* Rename the reflog file, if it exists. */
-	reference_has_log = git_reference_has_log(ref);
-	if (reference_has_log < 0)
-		return reference_has_log;
+	return 0;
+}
+
 
-	if (reference_has_log && (error = git_reflog_rename(git_reference_owner(ref), git_reference_name(ref), new_name)) < 0)
+int git_reference_rename(
+	git_reference **out,
+	git_reference *ref,
+	const char *new_name,
+	int force)
+{
+	git_signature *who;
+	int error;
+
+	/* Should we return an error if there is no default? */
+	if (((error = git_signature_default(&who, ref->db->repo)) < 0) &&
+	    ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
 		return error;
+	}
 
-	return 0;
+	error = reference__rename(out, ref, new_name, force, who, NULL);
+
+	git_signature_free(who);
+
+	return error;
+}
+
+int git_reference_rename_with_log(
+	git_reference **out,
+	git_reference *ref,
+	const char *new_name,
+	int force,
+	const git_signature *who,
+	const char * message)
+{
+	return reference__rename(out, ref, new_name, force, who, message);
 }
 
 int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
diff --git a/src/stash.c b/src/stash.c
index 083c2a4..66b1cd7 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -412,25 +412,12 @@ static int update_reflog(
 	const char *message)
 {
 	git_reference *stash;
-	git_reflog *reflog = NULL;
 	int error;
 
-	if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0)
-		goto cleanup;
+	error = git_reference_create_with_log(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1, stasher, message);
 
 	git_reference_free(stash);
 
-	if ((error = git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE) < 0))
-		goto cleanup;
-
-	if ((error = git_reflog_append(reflog, w_commit_oid, stasher, message)) < 0)
-		goto cleanup;
-
-	if ((error = git_reflog_write(reflog)) < 0)
-		goto cleanup;
-
-cleanup:
-	git_reflog_free(reflog);
 	return error;
 }
 
@@ -636,7 +623,11 @@ int git_stash_drop(
 		entry = git_reflog_entry_byindex(reflog, 0);
 
 		git_reference_free(stash);
-		error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1);
+		if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1) < 0))
+			goto cleanup;
+
+		/* We need to undo the writing that we just did */
+		error = git_reflog_write(reflog);
 	}
 
 cleanup:
diff --git a/tests/refs/createwithlog.c b/tests/refs/createwithlog.c
index ff36ffd..0fe81df 100644
--- a/tests/refs/createwithlog.c
+++ b/tests/refs/createwithlog.c
@@ -6,7 +6,6 @@
 #include "ref_helpers.h"
 
 static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
-static const char *current_head_target = "refs/heads/master";
 
 static git_repository *g_repo;
 
@@ -50,34 +49,3 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo
 	git_reference_free(reference);
 	git_signature_free(signature);
 }
-
-void test_refs_createwithlog__creating_a_symbolic_reference_adds_a_reflog_entry(void)
-{
-	git_reference *reference;
-	git_oid id;
-	git_signature *signature;
-	git_reflog *reflog;
-	const git_reflog_entry *entry;
-
-	const char *name = "ANOTHER_HEAD_TRACKER";
-	const char *message = "You've been logged, mate!";
-
-	git_oid_fromstr(&id, current_master_tip);
-
-	cl_git_pass(git_signature_now(&signature, "foo", "foo@bar"));
-
-	cl_git_pass(git_reference_symbolic_create_with_log(&reference, g_repo,
-		name, current_head_target, 0, signature, message));
-
-	cl_git_pass(git_reflog_read(&reflog, g_repo, name));
-	cl_assert_equal_sz(1, git_reflog_entrycount(reflog));
-
-	entry = git_reflog_entry_byindex(reflog, 0);
-	cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
-	cl_assert(git_oid_cmp(&id, &entry->oid_cur) == 0);
-	cl_assert_equal_s(message, entry->msg);
-
-	git_reflog_free(reflog);
-	git_reference_free(reference);
-	git_signature_free(signature);
-}
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index bcd2242..6008579 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -49,17 +49,20 @@ static void assert_appends(const git_signature *committer, const git_oid *oid)
 
 	/* Read and parse the reflog for this branch */
 	cl_git_pass(git_reflog_read(&reflog, repo2, new_ref));
-	cl_assert_equal_i(2, (int)git_reflog_entrycount(reflog));
+	cl_assert_equal_i(3, (int)git_reflog_entrycount(reflog));
+
+	/* The first one was the creation of the branch */
+	entry = git_reflog_entry_byindex(reflog, 2);
+	cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
 
 	entry = git_reflog_entry_byindex(reflog, 1);
 	assert_signature(committer, entry->committer);
-	cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+	cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
 	cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
 	cl_assert(entry->msg == NULL);
 
 	entry = git_reflog_entry_byindex(reflog, 0);
 	assert_signature(committer, entry->committer);
-	cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
 	cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
 	cl_assert_equal_s(commit_msg, entry->msg);
 
diff --git a/tests/refs/settargetwithlog.c b/tests/refs/settargetwithlog.c
index 99377da..cfa1c99 100644
--- a/tests/refs/settargetwithlog.c
+++ b/tests/refs/settargetwithlog.c
@@ -53,42 +53,3 @@ void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry
 	git_reference_free(reference);
 	git_signature_free(signature);
 }
-
-void test_refs_settargetwithlog__updating_a_symbolic_reference_adds_a_reflog_entry(void)
-{
-	git_reference *reference, *reference_out;
-	git_oid id;
-	git_signature *signature;
-	git_reflog *reflog;
-	const git_reflog_entry *entry;
-
-	const char *name = "HEAD";
-	const char *message = "You've been logged, mate!";
-
-	git_oid_fromstr(&id, br2_tip);
-
-	cl_git_pass(git_signature_now(&signature, "foo", "foo@bar"));
-	
-	cl_git_pass(git_reference_lookup(&reference, g_repo, name));
-
-	cl_assert_equal_s(
-		"refs/heads/master", git_reference_symbolic_target(reference));
-
-	cl_git_pass(git_reference_symbolic_set_target_with_log(&reference_out,
-		reference, br2_name, signature, message));
-
-	cl_assert_equal_s(
-		br2_name, git_reference_symbolic_target(reference_out));
-
-	cl_git_pass(git_reflog_read(&reflog, g_repo, name));
-
-	entry = git_reflog_entry_byindex(reflog, 0);
-	cl_assert(git_oid_streq(&entry->oid_old, master_tip) == 0);
-	cl_assert(git_oid_streq(&entry->oid_cur, br2_tip) == 0);
-	cl_assert_equal_s(message, entry->msg);
-
-	git_reflog_free(reflog);
-	git_reference_free(reference_out);
-	git_reference_free(reference);
-	git_signature_free(signature);
-}