Commit b4f5bb074721823cc016b66a9984abe2c271cb1f

Russell Belfer 2012-10-23T16:40:51

Initial implementation of diff rename detection This implements the basis for diff rename and copy detection, although it is based on simple SHA comparison right now instead of using a matching algortihm. Just as `git_diff_merge` can be used as a post-pass on diffs to emulate certain command line behaviors, there is a new API `git_diff_detect` which will update a diff list in-place, adjusting some deltas to RENAMED or COPIED state (and also, eventually, splitting MODIFIED deltas where the change is too large into DELETED/ADDED pairs). This also adds a new test repo that will hold rename/copy/split scenarios. Right now, it just has exact-match rename and copy, but the tests are written to use tree diffs, so we should be able to add new test scenarios easily without breaking tests.

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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 1932db0..f9dbb67 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -33,7 +33,7 @@ GIT_BEGIN_DECL
  * Flags for diff options.  A combination of these flags can be passed
  * in via the `flags` value in the `git_diff_options`.
  */
-enum {
+typedef enum {
 	/** Normal diff, the default */
 	GIT_DIFF_NORMAL = 0,
 	/** Reverse the sides of the diff */
@@ -86,7 +86,7 @@ enum {
 	 *  mode set to tree.  Note: the tree SHA will not be available.
 	 */
 	GIT_DIFF_INCLUDE_TYPECHANGE_TREES  = (1 << 16),
-};
+} git_diff_option_t;
 
 /**
  * Structure describing options about how the diff should be executed.
@@ -95,7 +95,7 @@ enum {
  * values.  Similarly, passing NULL for the options structure will
  * give the defaults.  The default values are marked below.
  *
- * - flags: a combination of the GIT_DIFF_... values above
+ * - flags: a combination of the git_diff_option_t values above
  * - context_lines: number of lines of context to show around diffs
  * - interhunk_lines: min lines between diff hunks to merge them
  * - old_prefix: "directory" to prefix to old file names (default "a")
@@ -124,7 +124,7 @@ typedef struct git_diff_list git_diff_list;
  * Most of the flags are just for internal consumption by libgit2,
  * but some of them may be interesting to external users.
  */
-enum {
+typedef enum {
 	GIT_DIFF_FILE_VALID_OID  = (1 << 0), /** `oid` value is known correct */
 	GIT_DIFF_FILE_FREE_PATH  = (1 << 1), /** `path` is allocated memory */
 	GIT_DIFF_FILE_BINARY     = (1 << 2), /** should be considered binary data */
@@ -132,7 +132,7 @@ enum {
 	GIT_DIFF_FILE_FREE_DATA  = (1 << 4), /** internal file data is allocated */
 	GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */
 	GIT_DIFF_FILE_NO_DATA    = (1 << 6), /** file data should not be loaded */
-};
+} git_diff_file_flag_t;
 
 /**
  * What type of change is described by a git_diff_delta?
@@ -218,7 +218,7 @@ typedef int (*git_diff_hunk_fn)(
  * output callbacks to demarcate lines that are actually part of
  * the file or hunk headers.
  */
-enum {
+typedef enum {
 	/* These values will be sent to `git_diff_data_fn` along with the line */
 	GIT_DIFF_LINE_CONTEXT   = ' ',
 	GIT_DIFF_LINE_ADDITION  = '+',
@@ -233,7 +233,7 @@ enum {
 	GIT_DIFF_LINE_FILE_HDR  = 'F',
 	GIT_DIFF_LINE_HUNK_HDR  = 'H',
 	GIT_DIFF_LINE_BINARY    = 'B'
-};
+} git_diff_line_t;
 
 /**
  * When iterating over a diff, callback that will be made per text diff
@@ -259,6 +259,36 @@ typedef int (*git_diff_data_fn)(
  */
 typedef struct git_diff_patch git_diff_patch;
 
+/**
+ * Flags to control the behavior of diff rename/copy detection.
+ */
+typedef enum {
+	/** should we look for renames */
+	GIT_DIFF_DETECT_RENAMES = (1 << 0),
+	/** should we look for copies */
+	GIT_DIFF_DETECT_COPIES   = (1 << 1),
+	/** should we consider unmodified files as possible copy sources */
+	GIT_DIFF_DETECT_COPIES_FROM_UNMODIFIED = (1 << 2),
+	/** should we split large rewrites into delete / add pairs */
+	GIT_DIFF_DETECT_BREAK_REWRITES = (1 << 3),
+} git_diff_detect_t;
+
+/**
+ * Control behavior of rename and copy detection
+ */
+typedef struct {
+	/** Combination of git_diff_detect_t values */
+	unsigned int flags;
+	/** Threshold on similarity index to consider a file renamed. */
+	unsigned int rename_threshold;
+	/** Threshold on similarity index to consider a file a copy. */
+	unsigned int copy_threshold;
+	/** Threshold on change % to split modify into delete/add pair. */
+	unsigned int break_rewrite_threshold;
+	/** Maximum rename/copy targets to check (diff.renameLimit) */
+	unsigned int target_limit;
+} git_diff_detect_options;
+
 
 /** @name Diff List Generator Functions
  *
@@ -374,6 +404,20 @@ GIT_EXTERN(int) git_diff_merge(
 	git_diff_list *onto,
 	const git_diff_list *from);
 
+/**
+ * Update a diff list with file renames, copies, etc.
+ *
+ * This modifies a diff list in place, replacing old entries that look
+ * like renames or copies with new entries reflecting those changes.
+ *
+ * @param diff Diff list to run detection algorithms on
+ * @param options Control how detection should be run, NULL for defaults
+ * @return 0 on success, -1 on failure
+ */
+GIT_EXTERN(int) git_diff_detect(
+	git_diff_list *diff,
+	git_diff_detect_options *options);
+
 /**@}*/
 
 
diff --git a/src/diff.c b/src/diff.c
index 9f693be..e2649ff 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -378,12 +378,23 @@ static git_diff_list *git_diff_list_alloc(
 		diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_CTIME;
 	/* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */
 
+	/* TODO: there are certain config settings where even if we were
+	 * not given an options structure, we need the diff list to have one
+	 * so that we can store the altered default values.
+	 *
+	 * - diff.ignoreSubmodules
+	 * - diff.mnemonicprefix
+	 * - diff.noprefix
+	 */
+
 	if (opts == NULL)
 		return diff;
 
 	memcpy(&diff->opts, opts, sizeof(git_diff_options));
 	memset(&diff->opts.pathspec, 0, sizeof(diff->opts.pathspec));
 
+	/* TODO: handle config diff.mnemonicprefix, diff.noprefix */
+
 	diff->opts.old_prefix = diff_strdup_prefix(&diff->pool,
 		opts->old_prefix ? opts->old_prefix : DIFF_OLD_PREFIX_DEFAULT);
 	diff->opts.new_prefix = diff_strdup_prefix(&diff->pool,
@@ -1082,3 +1093,139 @@ int git_diff_merge(
 
 	return error;
 }
+
+#define DEFAULT_THRESHOLD 50
+#define DEFAULT_TARGET_LIMIT 200
+
+int git_diff_detect(
+	git_diff_list *diff,
+	git_diff_detect_options *opts)
+{
+	int error = 0;
+	unsigned int i, j;
+	git_diff_delta *from, *to;
+	bool check_unmodified = opts &&
+		(opts->flags & GIT_DIFF_DETECT_COPIES_FROM_UNMODIFIED) != 0;
+	int max_targets = (opts && opts->target_limit > 0) ?
+		opts->target_limit : DEFAULT_TARGET_LIMIT;
+	unsigned int rename_threshold = (opts && opts->rename_threshold > 0) ?
+		opts->rename_threshold : DEFAULT_THRESHOLD;
+	unsigned int copy_threshold = (opts && opts->copy_threshold > 0) ?
+		opts->copy_threshold : DEFAULT_THRESHOLD;
+	int num_deletes = 0, num_splits = 0;
+
+	/* TODO: update opts from config diff.renameLimit / diff.renames */
+
+	git_vector_foreach(&diff->deltas, i, from) {
+		int tried_targets = 0;
+
+		git_vector_foreach(&diff->deltas, j, to) {
+			unsigned int similarity = 0;
+
+			if (i == j)
+				continue;
+
+			switch (to->status) {
+			case GIT_DELTA_ADDED:
+			case GIT_DELTA_UNTRACKED:
+			case GIT_DELTA_RENAMED:
+			case GIT_DELTA_COPIED:
+				break;
+			default:
+				/* only those status values should be checked */
+				continue;
+			}
+
+			/* don't check UNMODIFIED files as source unless given option */
+			if (from->status == GIT_DELTA_UNMODIFIED && !check_unmodified)
+				continue;
+
+			/* cap on maximum files we'll examine */
+			if (++tried_targets > max_targets)
+				break;
+
+			/* calculate similarity and see if this pair beats the
+			 * similarity score of the current best pair.
+			 */
+			if (git_oid_cmp(&from->old_file.oid, &to->new_file.oid) == 0)
+				similarity = 100;
+			/* TODO: insert actual similarity algo here */
+
+			if (similarity <= to->similarity)
+				continue;
+
+			if (from->status == GIT_DELTA_DELETED) {
+				if (similarity < rename_threshold)
+					continue;
+
+				/* merge "from" & "to" to a RENAMED record */
+				to->status = GIT_DELTA_RENAMED;
+				memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
+
+				from->status = GIT_DELTA__TO_DELETE;
+				num_deletes++;
+			} else {
+				if (similarity < copy_threshold)
+					continue;
+
+				/* convert "to" to a COPIED record */
+				to->status = GIT_DELTA_COPIED;
+				memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
+			}
+		}
+
+		if (from->status == GIT_DELTA_MODIFIED &&
+			opts && (opts->flags & GIT_DIFF_DETECT_BREAK_REWRITES) != 0)
+		{
+			/* TODO: calculate similarity and maybe mark for split */
+
+			/* from->status = GIT_DELTA__TO_SPLIT; */
+			/* num_splits++; */
+		}
+	}
+
+	if (num_deletes > 0 || num_splits > 0) {
+		git_vector onto = GIT_VECTOR_INIT;
+		size_t new_size = diff->deltas.length + num_splits - num_deletes;
+
+		if (git_vector_init(&onto, new_size, diff_delta__cmp) < 0)
+			return -1;
+
+		/* build new delta list without TO_DELETE and splitting TO_SPLIT */
+		git_vector_foreach(&diff->deltas, i, from) {
+			if (from->status == GIT_DELTA__TO_DELETE) {
+				git__free(from);
+				continue;
+			}
+
+			if (from->status == GIT_DELTA__TO_SPLIT) {
+				git_diff_delta *deleted = diff_delta__dup(from, &diff->pool);
+				if (!deleted)
+					return -1;
+
+				deleted->status = GIT_DELTA_DELETED;
+				memset(&deleted->new_file, 0, sizeof(deleted->new_file));
+				deleted->new_file.path = deleted->old_file.path;
+				deleted->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
+
+				git_vector_insert(&onto, deleted);
+
+				from->status = GIT_DELTA_ADDED;
+				memset(&from->old_file, 0, sizeof(from->old_file));
+				from->old_file.path = from->new_file.path;
+				from->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
+			}
+
+			git_vector_insert(&onto, from);
+		}
+
+		/* swap new delta list into place */
+
+		git_vector_sort(&onto);
+		git_vector_swap(&diff->deltas, &onto);
+		git_vector_free(&onto);
+	}
+
+	return error;
+}
+
diff --git a/src/diff.h b/src/diff.h
index c6a26ae..61723bc 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -28,6 +28,9 @@ enum {
 	GIT_DIFFCAPS_USE_DEV          = (1 << 4), /* use st_dev? */
 };
 
+#define GIT_DELTA__TO_DELETE 10
+#define GIT_DELTA__TO_SPLIT  11
+
 struct git_diff_list {
 	git_refcount     rc;
 	git_repository   *repo;
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index d5cf41e..0a37e82 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -59,8 +59,8 @@ void test_diff_blob__can_compare_text_blobs(void)
 		a, b, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_mods);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(1, expected.hunks);
 	cl_assert_equal_i(6, expected.lines);
@@ -74,8 +74,8 @@ void test_diff_blob__can_compare_text_blobs(void)
 		b, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_mods);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(1, expected.hunks);
 	cl_assert_equal_i(15, expected.lines);
@@ -89,8 +89,8 @@ void test_diff_blob__can_compare_text_blobs(void)
 		a, c, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_mods);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(1, expected.hunks);
 	cl_assert_equal_i(13, expected.lines);
@@ -103,8 +103,8 @@ void test_diff_blob__can_compare_text_blobs(void)
 		c, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_mods);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(2, expected.hunks);
 	cl_assert_equal_i(14, expected.lines);
@@ -125,8 +125,8 @@ void test_diff_blob__can_compare_against_null_blobs(void)
 		d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_dels);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(1, expected.hunks);
 	cl_assert_equal_i(14, expected.hunk_old_lines);
@@ -140,8 +140,8 @@ void test_diff_blob__can_compare_against_null_blobs(void)
 		d, e, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_adds);
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(0, expected.files_binary);
 
 	cl_assert_equal_i(1, expected.hunks);
 	cl_assert_equal_i(14, expected.hunk_new_lines);
@@ -154,10 +154,9 @@ void test_diff_blob__can_compare_against_null_blobs(void)
 	cl_git_pass(git_diff_blobs(
 		alien, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	cl_assert(expected.at_least_one_of_them_is_binary == true);
-
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_dels);
+	cl_assert_equal_i(1, expected.files_binary);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_DELETED]);
 	cl_assert_equal_i(0, expected.hunks);
 	cl_assert_equal_i(0, expected.lines);
 
@@ -166,20 +165,19 @@ void test_diff_blob__can_compare_against_null_blobs(void)
 	cl_git_pass(git_diff_blobs(
 		NULL, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	cl_assert(expected.at_least_one_of_them_is_binary == true);
-
 	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_adds);
+	cl_assert_equal_i(1, expected.files_binary);
+	cl_assert_equal_i(1, expected.file_status[GIT_DELTA_ADDED]);
 	cl_assert_equal_i(0, expected.hunks);
 	cl_assert_equal_i(0, expected.lines);
 }
 
-static void assert_identical_blobs_comparison(diff_expects expected)
+static void assert_identical_blobs_comparison(diff_expects *expected)
 {
-	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_unmodified);
-	cl_assert_equal_i(0, expected.hunks);
-	cl_assert_equal_i(0, expected.lines);
+	cl_assert_equal_i(1, expected->files);
+	cl_assert_equal_i(1, expected->file_status[GIT_DELTA_UNMODIFIED]);
+	cl_assert_equal_i(0, expected->hunks);
+	cl_assert_equal_i(0, expected->lines);
 }
 
 void test_diff_blob__can_compare_identical_blobs(void)
@@ -187,32 +185,32 @@ void test_diff_blob__can_compare_identical_blobs(void)
 	cl_git_pass(git_diff_blobs(
 		d, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
-	assert_identical_blobs_comparison(expected);
+	cl_assert_equal_i(0, expected.files_binary);
+	assert_identical_blobs_comparison(&expected);
 
 	memset(&expected, 0, sizeof(expected));
 	cl_git_pass(git_diff_blobs(
 		NULL, NULL, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	cl_assert(expected.at_least_one_of_them_is_binary == false);
-	assert_identical_blobs_comparison(expected);
+	cl_assert_equal_i(0, expected.files_binary);
+	assert_identical_blobs_comparison(&expected);
 
 	memset(&expected, 0, sizeof(expected));
 	cl_git_pass(git_diff_blobs(
 		alien, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	cl_assert(expected.at_least_one_of_them_is_binary == true);
-	assert_identical_blobs_comparison(expected);
+	cl_assert(expected.files_binary > 0);
+	assert_identical_blobs_comparison(&expected);
 }
 
-static void assert_binary_blobs_comparison(diff_expects expected)
+static void assert_binary_blobs_comparison(diff_expects *expected)
 {
-	cl_assert(expected.at_least_one_of_them_is_binary == true);
+	cl_assert(expected->files_binary > 0);
 
-	cl_assert_equal_i(1, expected.files);
-	cl_assert_equal_i(1, expected.file_mods);
-	cl_assert_equal_i(0, expected.hunks);
-	cl_assert_equal_i(0, expected.lines);
+	cl_assert_equal_i(1, expected->files);
+	cl_assert_equal_i(1, expected->file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, expected->hunks);
+	cl_assert_equal_i(0, expected->lines);
 }
 
 void test_diff_blob__can_compare_two_binary_blobs(void)
@@ -227,14 +225,14 @@ void test_diff_blob__can_compare_two_binary_blobs(void)
 	cl_git_pass(git_diff_blobs(
 		alien, heart, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	assert_binary_blobs_comparison(expected);
+	assert_binary_blobs_comparison(&expected);
 
 	memset(&expected, 0, sizeof(expected));
 
 	cl_git_pass(git_diff_blobs(
 		heart, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	assert_binary_blobs_comparison(expected);
+	assert_binary_blobs_comparison(&expected);
 
 	git_blob_free(heart);
 }
@@ -244,14 +242,14 @@ void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void)
 	cl_git_pass(git_diff_blobs(
 		alien, d, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	assert_binary_blobs_comparison(expected);
+	assert_binary_blobs_comparison(&expected);
 
 	memset(&expected, 0, sizeof(expected));
 
 	cl_git_pass(git_diff_blobs(
 		d, alien, &opts, &expected, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
-	assert_binary_blobs_comparison(expected);
+	assert_binary_blobs_comparison(&expected);
 }
 
 /*
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index de0e7e0..992c87d 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -32,20 +32,13 @@ int diff_file_fn(
 
 	e->files++;
 
-	if (delta->binary) {
-		e->at_least_one_of_them_is_binary = true;
+	if (delta->binary)
 		e->files_binary++;
-	}
 
-	switch (delta->status) {
-	case GIT_DELTA_ADDED: e->file_adds++; break;
-	case GIT_DELTA_DELETED: e->file_dels++; break;
-	case GIT_DELTA_MODIFIED: e->file_mods++; break;
-	case GIT_DELTA_IGNORED: e->file_ignored++; break;
-	case GIT_DELTA_UNTRACKED: e->file_untracked++; break;
-	case GIT_DELTA_UNMODIFIED: e->file_unmodified++; break;
-	default: break;
-	}
+	cl_assert(delta->status <= GIT_DELTA_TYPECHANGE);
+
+	e->file_status[delta->status] += 1;
+
 	return 0;
 }
 
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index 6291309..6ff493d 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -8,12 +8,7 @@ typedef struct {
 	int files;
 	int files_binary;
 
-	int file_adds;
-	int file_dels;
-	int file_mods;
-	int file_ignored;
-	int file_untracked;
-	int file_unmodified;
+	int file_status[10]; /* indexed by git_delta_t value */
 
 	int hunks;
 	int hunk_new_lines;
@@ -23,8 +18,6 @@ typedef struct {
 	int line_ctxt;
 	int line_adds;
 	int line_dels;
-
-	bool at_least_one_of_them_is_binary;
 } diff_expects;
 
 extern int diff_file_fn(
diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c
index 7c4bddb..eda8f06 100644
--- a/tests-clar/diff/index.c
+++ b/tests-clar/diff/index.c
@@ -45,9 +45,9 @@ void test_diff_index__0(void)
 	 * - mv .git .gitted
 	 */
 	cl_assert_equal_i(8, exp.files);
-	cl_assert_equal_i(3, exp.file_adds);
-	cl_assert_equal_i(2, exp.file_dels);
-	cl_assert_equal_i(3, exp.file_mods);
+	cl_assert_equal_i(3, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(8, exp.hunks);
 
@@ -73,9 +73,9 @@ void test_diff_index__0(void)
 	 * - mv .git .gitted
 	 */
 	cl_assert_equal_i(12, exp.files);
-	cl_assert_equal_i(7, exp.file_adds);
-	cl_assert_equal_i(2, exp.file_dels);
-	cl_assert_equal_i(3, exp.file_mods);
+	cl_assert_equal_i(7, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(12, exp.hunks);
 
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
new file mode 100644
index 0000000..8a50fd5
--- /dev/null
+++ b/tests-clar/diff/rename.c
@@ -0,0 +1,105 @@
+#include "clar_libgit2.h"
+#include "diff_helpers.h"
+
+static git_repository *g_repo = NULL;
+
+void test_diff_rename__initialize(void)
+{
+	g_repo = cl_git_sandbox_init("renames");
+}
+
+void test_diff_rename__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+}
+
+/*
+ * Renames repo has:
+ *
+ * commit 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 -
+ *   serving.txt     (25 lines)
+ *   sevencities.txt (50 lines)
+ * commit 2bc7f351d20b53f1c72c16c4b036e491c478c49a -
+ *   serving.txt     -> sixserving.txt  (rename, no change, 100% match)
+ *   sevencities.txt -> sevencities.txt (no change)
+ *   sevencities.txt -> songofseven.txt (copy, no change, 100% match)
+ *
+ * TODO: add commits with various % changes of copy / rename
+ */
+
+void test_diff_rename__match_oid(void)
+{
+	const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
+	const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
+	git_tree *old_tree, *new_tree;
+	git_diff_list *diff;
+	git_diff_options diffopts = {0};
+	git_diff_detect_options opts;
+	diff_expects exp;
+
+	old_tree = resolve_commit_oid_to_tree(g_repo, old_sha);
+	new_tree = resolve_commit_oid_to_tree(g_repo, new_sha);
+
+	/* Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
+	 * --find-copies-harder during rename detection...
+	 */
+	memset(&diffopts, 0, sizeof(diffopts));
+	diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
+
+	cl_git_pass(git_diff_tree_to_tree(
+		g_repo, &diffopts, old_tree, new_tree, &diff));
+
+	/* git diff --no-renames \
+	 *          31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+	 *          2bc7f351d20b53f1c72c16c4b036e491c478c49a
+	 */
+	memset(&exp, 0, sizeof(exp));
+	cl_git_pass(git_diff_foreach(
+		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+	cl_assert_equal_i(4, exp.files);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+
+	/* git diff 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+	 *          2bc7f351d20b53f1c72c16c4b036e491c478c49a
+	 */
+	cl_git_pass(git_diff_detect(diff, NULL));
+
+	memset(&exp, 0, sizeof(exp));
+	cl_git_pass(git_diff_foreach(
+		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+	cl_assert_equal_i(3, exp.files);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+
+	git_diff_list_free(diff);
+
+	cl_git_pass(git_diff_tree_to_tree(
+		g_repo, &diffopts, old_tree, new_tree, &diff));
+
+	/* git diff --find-copies-harder \
+	 *          31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
+	 *          2bc7f351d20b53f1c72c16c4b036e491c478c49a
+	 */
+	memset(&opts, 0, sizeof(opts));
+	opts.flags = GIT_DIFF_DETECT_COPIES_FROM_UNMODIFIED;
+	cl_git_pass(git_diff_detect(diff, &opts));
+
+	memset(&exp, 0, sizeof(exp));
+	cl_git_pass(git_diff_foreach(
+		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
+
+	cl_assert_equal_i(3, exp.files);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+
+	git_diff_list_free(diff);
+
+	git_tree_free(old_tree);
+	git_tree_free(new_tree);
+}
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index c5a0e62..f8b9a71 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -40,9 +40,9 @@ void test_diff_tree__0(void)
 		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(5, exp.files);
-	cl_assert_equal_i(2, exp.file_adds);
-	cl_assert_equal_i(1, exp.file_dels);
-	cl_assert_equal_i(2, exp.file_mods);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(5, exp.hunks);
 
@@ -62,9 +62,9 @@ void test_diff_tree__0(void)
 		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(2, exp.files);
-	cl_assert_equal_i(0, exp.file_adds);
-	cl_assert_equal_i(0, exp.file_dels);
-	cl_assert_equal_i(2, exp.file_mods);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(2, exp.hunks);
 
@@ -111,22 +111,23 @@ void test_diff_tree__options(void)
 	 * - git diff [options] 6bab5c79cd5140d0 605812ab7fe421fdd
 	 * - mv .git .gitted
 	 */
+#define EXPECT_STATUS_ADM(ADDS,DELS,MODS) { 0, ADDS, DELS, MODS, 0, 0, 0, 0, 0 }
 	diff_expects test_expects[] = {
 		/* a vs b tests */
-		{ 5, 0, 3, 0, 2, 0, 0, 0, 4, 0, 0, 51, 2, 46, 3 },
-		{ 5, 0, 3, 0, 2, 0, 0, 0, 4, 0, 0, 53, 4, 46, 3 },
-		{ 5, 0, 0, 3, 2, 0, 0, 0, 4, 0, 0, 52, 3, 3, 46 },
-		{ 5, 0, 3, 0, 2, 0, 0, 0, 5, 0, 0, 54, 3, 47, 4 },
+		{ 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 51, 2, 46, 3 },
+		{ 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 4, 0, 0, 53, 4, 46, 3 },
+		{ 5, 0, EXPECT_STATUS_ADM(0, 3, 2), 4, 0, 0, 52, 3, 3, 46 },
+		{ 5, 0, EXPECT_STATUS_ADM(3, 0, 2), 5, 0, 0, 54, 3, 47, 4 },
 		/* c vs d tests */
-		{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 22, 9, 10, 3 },
-		{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19, 12, 7, 0 },
-		{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 },
-		{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 },
-		{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 18, 11, 0, 7 },
+		{ 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 22, 9, 10, 3 },
+		{ 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 19, 12, 7, 0 },
+		{ 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 20, 11, 8, 1 },
+		{ 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 20, 11, 8, 1 },
+		{ 1, 0, EXPECT_STATUS_ADM(0, 0, 1), 1, 0, 0, 18, 11, 0, 7 },
 		{ 0 },
 	};
 	diff_expects *expected;
-	int i;
+	int i, j;
 
 	g_repo = cl_git_sandbox_init("attr");
 
@@ -149,9 +150,8 @@ void test_diff_tree__options(void)
 
 		expected = &test_expects[i];
 		cl_assert_equal_i(actual.files,     expected->files);
-		cl_assert_equal_i(actual.file_adds, expected->file_adds);
- 		cl_assert_equal_i(actual.file_dels, expected->file_dels);
-		cl_assert_equal_i(actual.file_mods, expected->file_mods);
+		for (j = GIT_DELTA_UNMODIFIED; j <= GIT_DELTA_TYPECHANGE; ++j)
+			cl_assert_equal_i(expected->file_status[j], actual.file_status[j]);
 		cl_assert_equal_i(actual.hunks,     expected->hunks);
 		cl_assert_equal_i(actual.lines,     expected->lines);
 		cl_assert_equal_i(actual.line_ctxt, expected->line_ctxt);
@@ -193,9 +193,9 @@ void test_diff_tree__bare(void)
 		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(3, exp.files);
-	cl_assert_equal_i(2, exp.file_adds);
-	cl_assert_equal_i(0, exp.file_dels);
-	cl_assert_equal_i(1, exp.file_mods);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(3, exp.hunks);
 
@@ -243,9 +243,9 @@ void test_diff_tree__merge(void)
 		diff1, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(6, exp.files);
-	cl_assert_equal_i(2, exp.file_adds);
-	cl_assert_equal_i(1, exp.file_dels);
-	cl_assert_equal_i(3, exp.file_mods);
+	cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
 
 	cl_assert_equal_i(6, exp.hunks);
 
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 3e388ea..e617560 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -46,11 +46,11 @@ void test_diff_workdir__to_index(void)
 		 * - mv .git .gitted
 		 */
 		cl_assert_equal_i(13, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(4, exp.file_dels);
-		cl_assert_equal_i(4, exp.file_mods);
-		cl_assert_equal_i(1, exp.file_ignored);
-		cl_assert_equal_i(4, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
 
 		cl_assert_equal_i(8, exp.hunks);
 
@@ -107,11 +107,11 @@ void test_diff_workdir__to_tree(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(14, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(4, exp.file_dels);
-		cl_assert_equal_i(4, exp.file_mods);
-		cl_assert_equal_i(1, exp.file_ignored);
-		cl_assert_equal_i(5, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(5, exp.file_status[GIT_DELTA_UNTRACKED]);
 	}
 
 	/* Since there is no git diff equivalent, let's just assume that the
@@ -143,11 +143,11 @@ void test_diff_workdir__to_tree(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(15, exp.files);
-		cl_assert_equal_i(2, exp.file_adds);
-		cl_assert_equal_i(5, exp.file_dels);
-		cl_assert_equal_i(4, exp.file_mods);
-		cl_assert_equal_i(1, exp.file_ignored);
-		cl_assert_equal_i(3, exp.file_untracked);
+		cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(5, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
 
 		cl_assert_equal_i(11, exp.hunks);
 
@@ -180,11 +180,11 @@ void test_diff_workdir__to_tree(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(16, exp.files);
-		cl_assert_equal_i(5, exp.file_adds);
-		cl_assert_equal_i(4, exp.file_dels);
-		cl_assert_equal_i(3, exp.file_mods);
-		cl_assert_equal_i(1, exp.file_ignored);
-		cl_assert_equal_i(3, exp.file_untracked);
+		cl_assert_equal_i(5, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
 
 		cl_assert_equal_i(12, exp.hunks);
 
@@ -228,11 +228,11 @@ void test_diff_workdir__to_index_with_pathspec(void)
 			cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
 
 		cl_assert_equal_i(13, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(4, exp.file_dels);
-		cl_assert_equal_i(4, exp.file_mods);
-		cl_assert_equal_i(1, exp.file_ignored);
-		cl_assert_equal_i(4, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
 	}
 
 	git_diff_list_free(diff);
@@ -251,11 +251,11 @@ void test_diff_workdir__to_index_with_pathspec(void)
 			cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
-		cl_assert_equal_i(0, exp.file_ignored);
-		cl_assert_equal_i(0, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
 	}
 
 	git_diff_list_free(diff);
@@ -274,11 +274,11 @@ void test_diff_workdir__to_index_with_pathspec(void)
 			cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
 
 		cl_assert_equal_i(3, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(1, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
-		cl_assert_equal_i(0, exp.file_ignored);
-		cl_assert_equal_i(1, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
 	}
 
 	git_diff_list_free(diff);
@@ -297,11 +297,11 @@ void test_diff_workdir__to_index_with_pathspec(void)
 			cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL));
 
 		cl_assert_equal_i(2, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(2, exp.file_dels);
-		cl_assert_equal_i(0, exp.file_mods);
-		cl_assert_equal_i(0, exp.file_ignored);
-		cl_assert_equal_i(0, exp.file_untracked);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
 	}
 
 	git_diff_list_free(diff);
@@ -337,7 +337,7 @@ void test_diff_workdir__filemode_changes(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(0, exp.files);
-		cl_assert_equal_i(0, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(0, exp.hunks);
 	}
 
@@ -360,7 +360,7 @@ void test_diff_workdir__filemode_changes(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(0, exp.hunks);
 	}
 
@@ -393,7 +393,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
 		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(0, exp.files);
-	cl_assert_equal_i(0, exp.file_mods);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
 	cl_assert_equal_i(0, exp.hunks);
 
 	git_diff_list_free(diff);
@@ -409,7 +409,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
 		diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 	cl_assert_equal_i(0, exp.files);
-	cl_assert_equal_i(0, exp.file_mods);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
 	cl_assert_equal_i(0, exp.hunks);
 
 	git_diff_list_free(diff);
@@ -456,9 +456,9 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
 				diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(1, exp.hunks);
 		cl_assert_equal_i(2, exp.lines);
 		cl_assert_equal_i(1, exp.line_ctxt);
@@ -477,9 +477,9 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
 				diff_w2i, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(1, exp.hunks);
 		cl_assert_equal_i(3, exp.lines);
 		cl_assert_equal_i(2, exp.line_ctxt);
@@ -500,9 +500,9 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
 				diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(1, exp.hunks);
 		cl_assert_equal_i(3, exp.lines);
 		cl_assert_equal_i(1, exp.line_ctxt);
@@ -542,9 +542,9 @@ void test_diff_workdir__eof_newline_changes(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(0, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(0, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(0, exp.hunks);
 		cl_assert_equal_i(0, exp.lines);
 		cl_assert_equal_i(0, exp.line_ctxt);
@@ -569,9 +569,9 @@ void test_diff_workdir__eof_newline_changes(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(1, exp.hunks);
 		cl_assert_equal_i(2, exp.lines);
 		cl_assert_equal_i(1, exp.line_ctxt);
@@ -596,9 +596,9 @@ void test_diff_workdir__eof_newline_changes(void)
 				diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn));
 
 		cl_assert_equal_i(1, exp.files);
-		cl_assert_equal_i(0, exp.file_adds);
-		cl_assert_equal_i(0, exp.file_dels);
-		cl_assert_equal_i(1, exp.file_mods);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+		cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+		cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 		cl_assert_equal_i(1, exp.hunks);
 		cl_assert_equal_i(3, exp.lines);
 		cl_assert_equal_i(0, exp.line_ctxt);
@@ -801,11 +801,11 @@ void test_diff_workdir__submodules(void)
 
 	cl_assert_equal_i(10, exp.files);
 
-	cl_assert_equal_i(0, exp.file_adds);
-	cl_assert_equal_i(0, exp.file_dels);
-	cl_assert_equal_i(1, exp.file_mods);
-	cl_assert_equal_i(0, exp.file_ignored);
-	cl_assert_equal_i(9, exp.file_untracked);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
+	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
+	cl_assert_equal_i(9, exp.file_status[GIT_DELTA_UNTRACKED]);
 
 	/* the following numbers match "git diff 873585" exactly */
 
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c
index 2294716..58f525e 100644
--- a/tests-clar/repo/head.c
+++ b/tests-clar/repo/head.c
@@ -180,8 +180,6 @@ void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
 
 void test_repo_head__can_tell_if_an_orphaned_head_is_detached(void)
 {
-	git_reference *head;
-
 	make_head_orphaned(repo, NON_EXISTING_HEAD);
 
 	cl_assert_equal_i(false, git_repository_head_detached(repo));
diff --git a/tests-clar/resources/renames/.gitted/HEAD b/tests-clar/resources/renames/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/renames/.gitted/config b/tests-clar/resources/renames/.gitted/config
new file mode 100644
index 0000000..bb4d11c
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
+	precomposeunicode = false
diff --git a/tests-clar/resources/renames/.gitted/description b/tests-clar/resources/renames/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/renames/.gitted/index b/tests-clar/resources/renames/.gitted/index
new file mode 100644
index 0000000..1fc69fc
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/index differ
diff --git a/tests-clar/resources/renames/.gitted/info/exclude b/tests-clar/resources/renames/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests-clar/resources/renames/.gitted/logs/HEAD b/tests-clar/resources/renames/.gitted/logs/HEAD
new file mode 100644
index 0000000..34222ed
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/logs/HEAD
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 Russell Belfer <rb@github.com> 1351024687 -0700	commit (initial): Initial commit
+31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 2bc7f351d20b53f1c72c16c4b036e491c478c49a Russell Belfer <rb@github.com> 1351024817 -0700	commit: copy and rename with no change
diff --git a/tests-clar/resources/renames/.gitted/logs/refs/heads/master b/tests-clar/resources/renames/.gitted/logs/refs/heads/master
new file mode 100644
index 0000000..34222ed
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 Russell Belfer <rb@github.com> 1351024687 -0700	commit (initial): Initial commit
+31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 2bc7f351d20b53f1c72c16c4b036e491c478c49a Russell Belfer <rb@github.com> 1351024817 -0700	commit: copy and rename with no change
diff --git a/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7 b/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7
new file mode 100644
index 0000000..2ee8644
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/03/da7ad872536bd448da8d88eb7165338bf923a7 differ
diff --git a/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a b/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a
new file mode 100644
index 0000000..93f1ccb
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/2b/c7f351d20b53f1c72c16c4b036e491c478c49a differ
diff --git a/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2 b/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2
new file mode 100644
index 0000000..00ce532
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/31/e47d8c1fa36d7f8d537b96158e3f024de0a9f2 differ
diff --git a/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745 b/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745
new file mode 100644
index 0000000..24eac54
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/61/8c6f2f8740bd6049b2fb9eb93fc15726462745 differ
diff --git a/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba b/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba
new file mode 100644
index 0000000..5ee28a7
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/66/311f5cfbe7836c27510a3ba2f43e282e2c8bba differ
diff --git a/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113 b/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113
new file mode 100644
index 0000000..440b7be
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/ad/0a8e55a104ac54a8a29ed4b84b49e76837a113 differ
diff --git a/tests-clar/resources/renames/.gitted/refs/heads/master b/tests-clar/resources/renames/.gitted/refs/heads/master
new file mode 100644
index 0000000..049b1f5
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/refs/heads/master
@@ -0,0 +1 @@
+2bc7f351d20b53f1c72c16c4b036e491c478c49a
diff --git a/tests-clar/resources/renames/sevencities.txt b/tests-clar/resources/renames/sevencities.txt
new file mode 100644
index 0000000..66311f5
--- /dev/null
+++ b/tests-clar/resources/renames/sevencities.txt
@@ -0,0 +1,49 @@
+The Song of Seven Cities
+========================
+
+I WAS Lord of Cities very sumptuously builded.
+Seven roaring Cities paid me tribute from afar.
+Ivory their outposts were—the guardrooms of them gilded,
+And garrisoned with Amazons invincible in war.
+
+All the world went softly when it walked before my Cities—
+Neither King nor Army vexed my peoples at their toil,
+Never horse nor chariot irked or overbore my Cities,
+Never Mob nor Ruler questioned whence they drew their spoil.
+
+Banded, mailed and arrogant from sunrise unto sunset;
+Singing while they sacked it, they possessed the land at large.
+Yet when men would rob them, they resisted, they made onset
+And pierced the smoke of battle with a thousand-sabred charge.
+
+So they warred and trafficked only yesterday, my Cities.
+To-day there is no mark or mound of where my Cities stood.
+For the River rose at midnight and it washed away my Cities.
+They are evened with Atlantis and the towns before the Flood.
+
+Rain on rain-gorged channels raised the water-levels round them,
+Freshet backed on freshet swelled and swept their world from sight,
+Till the emboldened floods linked arms and, flashing forward, drowned them—
+Drowned my Seven Cities and their peoples in one night!
+
+Low among the alders lie their derelict foundations,
+The beams wherein they trusted and the plinths whereon they built—
+My rulers and their treasure and their unborn populations,
+Dead, destroyed, aborted, and defiled with mud and silt!
+
+The Daughters of the Palace whom they cherished in my Cities,
+My silver-tongued Princesses, and the promise of their May—
+Their bridegrooms of the June-tide—all have perished in my Cities,
+With the harsh envenomed virgins that can neither love nor play.
+
+I was Lord of Cities—I will build anew my Cities,
+Seven, set on rocks, above the wrath of any flood.
+Nor will I rest from search till I have filled anew my Cities
+With peoples undefeated of the dark, enduring blood.
+
+To the sound of trumpets shall their seed restore my Cities
+Wealthy and well-weaponed, that once more may I behold
+All the world go softly when it walks before my Cities,
+And the horses and the chariots fleeing from them as of old!
+
+                -- Rudyard Kipling
diff --git a/tests-clar/resources/renames/sixserving.txt b/tests-clar/resources/renames/sixserving.txt
new file mode 100644
index 0000000..ad0a8e5
--- /dev/null
+++ b/tests-clar/resources/renames/sixserving.txt
@@ -0,0 +1,24 @@
+I KEEP six honest serving-men
+ (They taught me all I knew);
+Their names are What and Why and When
+ And How and Where and Who.
+I send them over land and sea,
+ I send them east and west;
+But after they have worked for me,
+ I give them all a rest.
+
+I let them rest from nine till five,
+ For I am busy then,
+As well as breakfast, lunch, and tea,
+ For they are hungry men.
+But different folk have different views;
+I know a person small—
+She keeps ten million serving-men,
+Who get no rest at all!
+
+She sends'em abroad on her own affairs,
+ From the second she opens her eyes—
+One million Hows, two million Wheres,
+And seven million Whys!
+
+                -- Rudyard Kipling
diff --git a/tests-clar/resources/renames/songofseven.txt b/tests-clar/resources/renames/songofseven.txt
new file mode 100644
index 0000000..66311f5
--- /dev/null
+++ b/tests-clar/resources/renames/songofseven.txt
@@ -0,0 +1,49 @@
+The Song of Seven Cities
+========================
+
+I WAS Lord of Cities very sumptuously builded.
+Seven roaring Cities paid me tribute from afar.
+Ivory their outposts were—the guardrooms of them gilded,
+And garrisoned with Amazons invincible in war.
+
+All the world went softly when it walked before my Cities—
+Neither King nor Army vexed my peoples at their toil,
+Never horse nor chariot irked or overbore my Cities,
+Never Mob nor Ruler questioned whence they drew their spoil.
+
+Banded, mailed and arrogant from sunrise unto sunset;
+Singing while they sacked it, they possessed the land at large.
+Yet when men would rob them, they resisted, they made onset
+And pierced the smoke of battle with a thousand-sabred charge.
+
+So they warred and trafficked only yesterday, my Cities.
+To-day there is no mark or mound of where my Cities stood.
+For the River rose at midnight and it washed away my Cities.
+They are evened with Atlantis and the towns before the Flood.
+
+Rain on rain-gorged channels raised the water-levels round them,
+Freshet backed on freshet swelled and swept their world from sight,
+Till the emboldened floods linked arms and, flashing forward, drowned them—
+Drowned my Seven Cities and their peoples in one night!
+
+Low among the alders lie their derelict foundations,
+The beams wherein they trusted and the plinths whereon they built—
+My rulers and their treasure and their unborn populations,
+Dead, destroyed, aborted, and defiled with mud and silt!
+
+The Daughters of the Palace whom they cherished in my Cities,
+My silver-tongued Princesses, and the promise of their May—
+Their bridegrooms of the June-tide—all have perished in my Cities,
+With the harsh envenomed virgins that can neither love nor play.
+
+I was Lord of Cities—I will build anew my Cities,
+Seven, set on rocks, above the wrath of any flood.
+Nor will I rest from search till I have filled anew my Cities
+With peoples undefeated of the dark, enduring blood.
+
+To the sound of trumpets shall their seed restore my Cities
+Wealthy and well-weaponed, that once more may I behold
+All the world go softly when it walks before my Cities,
+And the horses and the chariots fleeing from them as of old!
+
+                -- Rudyard Kipling