14
14
#include "diffcore.h"
15
15
#include "revision.h"
16
17
#include "xdiff-interface.h"
18
#include "cache-tree.h"
19
#include "path-list.h"
22
22
static char blame_usage[] =
23
"git-blame [-c] [-l] [-t] [-f] [-n] [-p] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [commit] [--] file\n"
24
" -c, --compatibility Use the same output mode as git-annotate (Default: off)\n"
25
" -l, --long Show long commit SHA1 (Default: off)\n"
26
" -t, --time Show raw timestamp (Default: off)\n"
23
"git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [commit] [--] file\n"
24
" -c Use the same output mode as git-annotate (Default: off)\n"
25
" -b Show blank SHA-1 for boundary commits (Default: off)\n"
26
" -l Show long commit SHA1 (Default: off)\n"
27
" --root Do not treat root commits as boundaries (Default: off)\n"
28
" -t Show raw timestamp (Default: off)\n"
27
29
" -f, --show-name Show original filename (Default: auto)\n"
28
30
" -n, --show-number Show original linenumber (Default: off)\n"
31
" -s Suppress author name and timestamp (Default: off)\n"
29
32
" -p, --porcelain Show in a format designed for machine consumption\n"
33
" -w Ignore whitespace differences\n"
30
34
" -L n,m Process only line range n,m, counting from 1\n"
31
35
" -M, -C Find line movements within and across files\n"
36
" --incremental Show blame entries as we find them, incrementally\n"
37
" --contents file Use <file>'s contents as the final image\n"
32
38
" -S revs-file Use revisions from revs-file instead of calling git-rev-list\n";
34
40
static int longest_file;
159
static int cmp_suspect(struct origin *a, struct origin *b)
194
static inline int same_suspect(struct origin *a, struct origin *b)
161
int cmp = hashcmp(a->commit->object.sha1, b->commit->object.sha1);
164
return strcmp(a->path, b->path);
198
if (a->commit != b->commit)
200
return !strcmp(a->path, b->path);
167
#define cmp_suspect(a, b) ( ((a)==(b)) ? 0 : cmp_suspect(a,b) )
169
203
static void sanity_check_refcnt(struct scoreboard *);
206
* If two blame entries that are next to each other came from
207
* contiguous lines in the same origin (i.e. <commit, path> pair),
208
* merge them together.
171
210
static void coalesce(struct scoreboard *sb)
173
212
struct blame_entry *ent, *next;
175
214
for (ent = sb->ent; ent && (next = ent->next); ent = next) {
176
if (!cmp_suspect(ent->suspect, next->suspect) &&
215
if (same_suspect(ent->suspect, next->suspect) &&
177
216
ent->guilty == next->guilty &&
178
217
ent->s_lno + ent->num_lines == next->s_lno) {
179
218
ent->num_lines += next->num_lines;
244
301
const char *paths[2];
246
303
if (parent->util) {
247
/* This is a freestanding copy of origin and not
305
* Each commit object can cache one origin in that
306
* commit. This is a freestanding copy of origin and
250
309
struct origin *cached = parent->util;
251
310
if (!strcmp(cached->path, origin->path)) {
312
* The same path between origin and its parent
313
* without renaming -- the most common case.
252
315
porigin = get_origin(sb, parent, cached->path);
318
* If the origin was newly created (i.e. get_origin
319
* would call make_origin if none is found in the
320
* scoreboard), it does not know the blob_sha1,
321
* so copy it. Otherwise porigin was in the
322
* scoreboard and already knows blob_sha1.
253
324
if (porigin->refcnt == 1)
254
325
hashcpy(porigin->blob_sha1, cached->blob_sha1);
513
620
return sb->final_buf + sb->lineno[lno];
624
* It is known that lines between tlno to same came from parent, and e
625
* has an overlap with that range. it also is known that parent's
626
* line plno corresponds to e's line tlno.
632
* <------------------>
634
* Split e into potentially three parts; before this chunk, the chunk
635
* to be blamed for the parent, and after that portion.
516
637
static void split_overlap(struct blame_entry *split,
517
638
struct blame_entry *e,
518
639
int tlno, int plno, int same,
519
640
struct origin *parent)
521
/* it is known that lines between tlno to same came from
522
* parent, and e has an overlap with that range. it also is
523
* known that parent's line plno corresponds to e's line tlno.
529
* <------------------>
531
* Potentially we need to split e into three parts; before
532
* this chunk, the chunk to be blamed for parent, and after
535
642
int chunk_end_lno;
536
643
memset(split, 0, sizeof(struct blame_entry [3]));
573
689
struct blame_entry *new_entry;
575
691
if (split[0].suspect && split[2].suspect) {
576
/* we need to split e into two and add another for parent */
692
/* The first part (reuse storage for the existing entry e) */
577
693
dup_entry(e, &split[0]);
695
/* The last part -- me */
579
696
new_entry = xmalloc(sizeof(*new_entry));
580
697
memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
581
698
add_blame_entry(sb, new_entry);
700
/* ... and the middle part -- parent */
583
701
new_entry = xmalloc(sizeof(*new_entry));
584
702
memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
585
703
add_blame_entry(sb, new_entry);
587
705
else if (!split[0].suspect && !split[2].suspect)
588
/* parent covers the entire area */
707
* The parent covers the entire area; reuse storage for
708
* e and replace it with the parent.
589
710
dup_entry(e, &split[1]);
590
711
else if (split[0].suspect) {
712
/* me and then parent */
591
713
dup_entry(e, &split[0]);
593
715
new_entry = xmalloc(sizeof(*new_entry));
695
839
plno = chunk->p_next;
696
840
tlno = chunk->t_next;
698
/* rest (i.e. anything above tlno) are the same as parent */
842
/* The rest (i.e. anything after tlno) are the same as the parent */
699
843
blame_chunk(sb, tlno, plno, last_in_target, target, parent);
701
845
free_patch(patch);
850
* The lines in blame_entry after splitting blames many times can become
851
* very small and trivial, and at some point it becomes pointless to
852
* blame the parents. E.g. "\t\t}\n\t}\n\n" appears everywhere in any
853
* ordinary C program, and it is not worth to say it was copied from
854
* totally unrelated file in the parent.
856
* Compute how trivial the lines in the blame_entry are.
705
858
static unsigned ent_score(struct scoreboard *sb, struct blame_entry *e)
742
901
memcpy(best_so_far, this, sizeof(struct blame_entry [3]));
905
* We are looking at a part of the final image represented by
906
* ent (tlno and same are offset by ent->s_lno).
907
* tlno is where we are looking at in the final image.
908
* up to (but not including) same match preimage.
909
* plno is where we are looking at in the preimage.
911
* <-------------- final image ---------------------->
914
* <---------preimage----->
917
* All line numbers are 0-based.
919
static void handle_split(struct scoreboard *sb,
920
struct blame_entry *ent,
921
int tlno, int plno, int same,
922
struct origin *parent,
923
struct blame_entry *split)
925
if (ent->num_lines <= tlno)
928
struct blame_entry this[3];
931
split_overlap(this, ent, tlno, plno, same, parent);
932
copy_split_if_better(sb, split, this);
938
* Find the lines from parent that are the same as ent so that
939
* we can pass blames to it. file_p has the blob contents for
745
942
static void find_copy_in_blob(struct scoreboard *sb,
746
943
struct blame_entry *ent,
747
944
struct origin *parent,
767
967
patch = compare_buffer(file_p, &file_o, 1);
970
* file_o is a part of final image we are annotating.
971
* file_p partially may match that image.
769
973
memset(split, 0, sizeof(struct blame_entry [3]));
771
975
for (i = 0; i < patch->num; i++) {
772
976
struct chunk *chunk = &patch->chunks[i];
774
/* tlno to chunk->same are the same as ent */
775
if (ent->num_lines <= tlno)
777
if (tlno < chunk->same) {
778
struct blame_entry this[3];
779
split_overlap(this, ent,
780
tlno + ent->s_lno, plno,
781
chunk->same + ent->s_lno,
783
copy_split_if_better(sb, split, this);
978
handle_split(sb, ent, tlno, plno, chunk->same, parent, split);
786
979
plno = chunk->p_next;
787
980
tlno = chunk->t_next;
982
/* remainder, if any, all match the preimage */
983
handle_split(sb, ent, tlno, plno, ent->num_lines, parent, split);
789
984
free_patch(patch);
988
* See if lines currently target is suspected for can be attributed to
792
991
static int find_move_in_parent(struct scoreboard *sb,
793
992
struct origin *target,
794
993
struct origin *parent)
837
1039
int num_ents, i;
838
1040
struct blame_list *blame_list = NULL;
840
/* Count the number of entries the target is suspected for,
841
* and prepare a list of entry and the best split.
843
1042
for (e = sb->ent, num_ents = 0; e; e = e->next)
844
if (!e->guilty && !cmp_suspect(e->suspect, target))
1043
if (!e->guilty && same_suspect(e->suspect, target))
847
1046
blame_list = xcalloc(num_ents, sizeof(struct blame_list));
848
1047
for (e = sb->ent, i = 0; e; e = e->next)
849
if (!e->guilty && !cmp_suspect(e->suspect, target))
1048
if (!e->guilty && same_suspect(e->suspect, target))
850
1049
blame_list[i++].ent = e;
852
1051
*num_ents_p = num_ents;
853
1052
return blame_list;
1056
* For lines target is suspected for, see if we can find code movement
1057
* across file boundary from the parent commit. porigin is the path
1058
* in the parent we already tried.
856
1060
static int find_copy_in_parent(struct scoreboard *sb,
857
1061
struct origin *target,
858
1062
struct commit *parent,
886
1090
* and this code needs to be after diff_setup_done(), which
887
1091
* usually makes find-copies-harder imply copy detection.
889
if ((opt & PICKAXE_BLAME_COPY_HARDER) &&
890
(!porigin || strcmp(target->path, porigin->path)))
1093
if ((opt & PICKAXE_BLAME_COPY_HARDEST)
1094
|| ((opt & PICKAXE_BLAME_COPY_HARDER)
1095
&& (!porigin || strcmp(target->path, porigin->path))))
891
1096
diff_opts.find_copies_harder = 1;
893
diff_tree_sha1(parent->tree->object.sha1,
894
target->commit->tree->object.sha1,
1098
if (is_null_sha1(target->commit->object.sha1))
1099
do_diff_cache(parent->tree->object.sha1, &diff_opts);
1101
diff_tree_sha1(parent->tree->object.sha1,
1102
target->commit->tree->object.sha1,
897
1105
if (!diff_opts.find_copies_harder)
898
1106
diffcore_std(&diff_opts);
1069
1278
origin_decref(parent_origin[i]);
1072
static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
1075
struct blame_entry *ent;
1076
struct commit *commit;
1077
struct origin *suspect = NULL;
1079
/* find one suspect to break down */
1080
for (ent = sb->ent; !suspect && ent; ent = ent->next)
1082
suspect = ent->suspect;
1084
return; /* all done */
1086
origin_incref(suspect);
1087
commit = suspect->commit;
1088
if (!commit->object.parsed)
1089
parse_commit(commit);
1090
if (!(commit->object.flags & UNINTERESTING) &&
1091
!(revs->max_age != -1 && commit->date < revs->max_age))
1092
pass_blame(sb, suspect, opt);
1094
/* Take responsibility for the remaining entries */
1095
for (ent = sb->ent; ent; ent = ent->next)
1096
if (!cmp_suspect(ent->suspect, suspect))
1098
origin_decref(suspect);
1100
if (DEBUG) /* sanity */
1101
sanity_check_refcnt(sb);
1105
static const char *format_time(unsigned long time, const char *tz_str,
1108
static char time_buf[128];
1113
if (show_raw_time) {
1114
sprintf(time_buf, "%lu %s", time, tz_str);
1119
minutes = tz < 0 ? -tz : tz;
1120
minutes = (minutes / 100)*60 + (minutes % 100);
1121
minutes = tz < 0 ? -minutes : minutes;
1122
t = time + minutes * 60;
1125
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S ", tm);
1126
strcat(time_buf, tz_str);
1282
* Information on commits, used for output.
1130
1284
struct commit_info
1287
const char *author_mail;
1134
1288
unsigned long author_time;
1289
const char *author_tz;
1137
1291
/* filled only when asked for details */
1139
char *committer_mail;
1292
const char *committer;
1293
const char *committer_mail;
1140
1294
unsigned long committer_time;
1295
const char *committer_tz;
1297
const char *summary;
1301
* Parse author/committer line in the commit object buffer
1146
1303
static void get_ac_line(const char *inbuf, const char *what,
1147
int bufsz, char *person, char **mail,
1148
unsigned long *time, char **tz)
1304
int bufsz, char *person, const char **mail,
1305
unsigned long *time, const char **tz)
1307
int len, tzlen, maillen;
1308
char *tmp, *endp, *timepos;
1153
1310
tmp = strstr(inbuf, what);
1174
1331
while (*tmp != ' ')
1334
tzlen = (person+len)-(tmp+1);
1179
1337
while (*tmp != ' ')
1181
1339
*time = strtoul(tmp, NULL, 10);
1184
1343
while (*tmp != ' ')
1186
1345
*mail = tmp + 1;
1347
maillen = timepos - tmp;
1353
* mailmap expansion may make the name longer.
1354
* make room by pushing stuff down.
1356
tmp = person + bufsz - (tzlen + 1);
1357
memmove(tmp, *tz, tzlen);
1361
tmp = tmp - (maillen + 1);
1362
memmove(tmp, *mail, maillen);
1367
* Now, convert e-mail using mailmap
1369
map_email(&mailmap, tmp + 1, person, tmp-person-1);
1190
1372
static void get_commit_info(struct commit *commit,
1197
1379
static char committer_buf[1024];
1198
1380
static char summary_buf[1024];
1200
/* We've operated without save_commit_buffer, so
1383
* We've operated without save_commit_buffer, so
1201
1384
* we now need to populate them for output.
1203
1386
if (!commit->buffer) {
1387
enum object_type type;
1205
1388
unsigned long size;
1206
1389
commit->buffer =
1207
read_sha1_file(commit->object.sha1, type, &size);
1390
read_sha1_file(commit->object.sha1, &type, &size);
1391
if (!commit->buffer)
1392
die("Cannot read commit %s",
1393
sha1_to_hex(commit->object.sha1));
1209
1395
ret->author = author_buf;
1210
1396
get_ac_line(commit->buffer, "\nauthor ",
1230
1416
endp = strchr(tmp, '\n');
1418
endp = tmp + strlen(tmp);
1233
1419
len = endp - tmp;
1234
if (len >= sizeof(summary_buf))
1420
if (len >= sizeof(summary_buf) || len == 0)
1235
1421
goto error_out;
1236
1422
memcpy(summary_buf, tmp, len);
1237
1423
summary_buf[len] = 0;
1427
* To allow LF and other nonportable characters in pathnames,
1428
* they are c-style quoted as needed.
1430
static void write_filename_info(const char *path)
1432
printf("filename ");
1433
write_name_quoted(NULL, 0, path, 1, stdout);
1438
* The blame_entry is found to be guilty for the range. Mark it
1439
* as such, and show it in incremental output.
1441
static void found_guilty_entry(struct blame_entry *ent)
1447
struct origin *suspect = ent->suspect;
1449
printf("%s %d %d %d\n",
1450
sha1_to_hex(suspect->commit->object.sha1),
1451
ent->s_lno + 1, ent->lno + 1, ent->num_lines);
1452
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
1453
struct commit_info ci;
1454
suspect->commit->object.flags |= METAINFO_SHOWN;
1455
get_commit_info(suspect->commit, &ci, 1);
1456
printf("author %s\n", ci.author);
1457
printf("author-mail %s\n", ci.author_mail);
1458
printf("author-time %lu\n", ci.author_time);
1459
printf("author-tz %s\n", ci.author_tz);
1460
printf("committer %s\n", ci.committer);
1461
printf("committer-mail %s\n", ci.committer_mail);
1462
printf("committer-time %lu\n", ci.committer_time);
1463
printf("committer-tz %s\n", ci.committer_tz);
1464
printf("summary %s\n", ci.summary);
1465
if (suspect->commit->object.flags & UNINTERESTING)
1466
printf("boundary\n");
1468
write_filename_info(suspect->path);
1469
maybe_flush_or_die(stdout, "stdout");
1474
* The main loop -- while the scoreboard has lines whose true origin
1475
* is still unknown, pick one blame_entry, and allow its current
1476
* suspect to pass blames to its parents.
1478
static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
1481
struct blame_entry *ent;
1482
struct commit *commit;
1483
struct origin *suspect = NULL;
1485
/* find one suspect to break down */
1486
for (ent = sb->ent; !suspect && ent; ent = ent->next)
1488
suspect = ent->suspect;
1490
return; /* all done */
1493
* We will use this suspect later in the loop,
1494
* so hold onto it in the meantime.
1496
origin_incref(suspect);
1497
commit = suspect->commit;
1498
if (!commit->object.parsed)
1499
parse_commit(commit);
1500
if (!(commit->object.flags & UNINTERESTING) &&
1501
!(revs->max_age != -1 && commit->date < revs->max_age))
1502
pass_blame(sb, suspect, opt);
1504
commit->object.flags |= UNINTERESTING;
1505
if (commit->object.parsed)
1506
mark_parents_uninteresting(commit);
1508
/* treat root commit as boundary */
1509
if (!commit->parents && !show_root)
1510
commit->object.flags |= UNINTERESTING;
1512
/* Take responsibility for the remaining entries */
1513
for (ent = sb->ent; ent; ent = ent->next)
1514
if (same_suspect(ent->suspect, suspect))
1515
found_guilty_entry(ent);
1516
origin_decref(suspect);
1518
if (DEBUG) /* sanity */
1519
sanity_check_refcnt(sb);
1523
static const char *format_time(unsigned long time, const char *tz_str,
1526
static char time_buf[128];
1531
if (show_raw_time) {
1532
sprintf(time_buf, "%lu %s", time, tz_str);
1537
minutes = tz < 0 ? -tz : tz;
1538
minutes = (minutes / 100)*60 + (minutes % 100);
1539
minutes = tz < 0 ? -minutes : minutes;
1540
t = time + minutes * 60;
1543
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S ", tm);
1544
strcat(time_buf, tz_str);
1240
1548
#define OUTPUT_ANNOTATE_COMPAT 001
1241
1549
#define OUTPUT_LONG_OBJECT_NAME 002
1242
1550
#define OUTPUT_RAW_TIMESTAMP 004
1271
1580
printf("committer-mail %s\n", ci.committer_mail);
1272
1581
printf("committer-time %lu\n", ci.committer_time);
1273
1582
printf("committer-tz %s\n", ci.committer_tz);
1274
printf("filename %s\n", suspect->path);
1583
write_filename_info(suspect->path);
1275
1584
printf("summary %s\n", ci.summary);
1585
if (suspect->commit->object.flags & UNINTERESTING)
1586
printf("boundary\n");
1277
1588
else if (suspect->commit->object.flags & MORE_THAN_ONE_PATH)
1278
printf("filename %s\n", suspect->path);
1589
write_filename_info(suspect->path);
1280
1591
cp = nth_line(sb, ent->lno);
1281
1592
for (cnt = 0; cnt < ent->num_lines; cnt++) {
1308
1619
cp = nth_line(sb, ent->lno);
1309
1620
for (cnt = 0; cnt < ent->num_lines; cnt++) {
1312
printf("%.*s", (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8, hex);
1622
int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8;
1624
if (suspect->commit->object.flags & UNINTERESTING) {
1626
memset(hex, ' ', length);
1627
else if (!cmd_is_annotate) {
1633
printf("%.*s", length, hex);
1313
1634
if (opt & OUTPUT_ANNOTATE_COMPAT)
1314
1635
printf("\t(%10s\t%10s\t%d)", ci.author,
1315
1636
format_time(ci.author_time, ci.author_tz,
1626
1983
usage(blame_usage);
1986
static int git_blame_config(const char *var, const char *value)
1988
if (!strcmp(var, "blame.showroot")) {
1989
show_root = git_config_bool(var, value);
1992
if (!strcmp(var, "blame.blankboundary")) {
1993
blank_boundary = git_config_bool(var, value);
1996
return git_default_config(var, value);
1999
static struct commit *fake_working_tree_commit(const char *path, const char *contents_from)
2001
struct commit *commit;
2002
struct origin *origin;
2003
unsigned char head_sha1[20];
2008
unsigned long fin_size;
2010
struct cache_entry *ce;
2013
if (get_sha1("HEAD", head_sha1))
2014
die("No such ref: HEAD");
2017
commit = xcalloc(1, sizeof(*commit));
2018
commit->parents = xcalloc(1, sizeof(*commit->parents));
2019
commit->parents->item = lookup_commit_reference(head_sha1);
2020
commit->object.parsed = 1;
2022
commit->object.type = OBJ_COMMIT;
2024
origin = make_origin(commit, path);
2026
if (!contents_from || strcmp("-", contents_from)) {
2028
const char *read_from;
2030
if (contents_from) {
2031
if (stat(contents_from, &st) < 0)
2032
die("Cannot stat %s", contents_from);
2033
read_from = contents_from;
2036
if (lstat(path, &st) < 0)
2037
die("Cannot lstat %s", path);
2040
fin_size = xsize_t(st.st_size);
2041
buf = xmalloc(fin_size+1);
2042
mode = canon_mode(st.st_mode);
2043
switch (st.st_mode & S_IFMT) {
2045
fd = open(read_from, O_RDONLY);
2047
die("cannot open %s", read_from);
2048
if (read_in_full(fd, buf, fin_size) != fin_size)
2049
die("cannot read %s", read_from);
2052
if (readlink(read_from, buf, fin_size+1) != fin_size)
2053
die("cannot readlink %s", read_from);
2056
die("unsupported file type %s", read_from);
2060
/* Reading from stdin */
2061
contents_from = "standard input";
2067
buf = xrealloc(buf, fin_size + cnt);
2068
cnt = xread(0, buf + fin_size, cnt);
2070
die("read error %s from stdin",
2076
buf = xrealloc(buf, fin_size + 1);
2079
origin->file.ptr = buf;
2080
origin->file.size = fin_size;
2081
pretend_sha1_file(buf, fin_size, OBJ_BLOB, origin->blob_sha1);
2082
commit->util = origin;
2085
* Read the current index, replace the path entry with
2086
* origin->blob_sha1 without mucking with its mode or type
2087
* bits; we are not going to write this index out -- we just
2088
* want to run "diff-index --cached".
2095
int pos = cache_name_pos(path, len);
2097
mode = ntohl(active_cache[pos]->ce_mode);
2099
/* Let's not bother reading from HEAD tree */
2100
mode = S_IFREG | 0644;
2102
size = cache_entry_size(len);
2103
ce = xcalloc(1, size);
2104
hashcpy(ce->sha1, origin->blob_sha1);
2105
memcpy(ce->name, path, len);
2106
ce->ce_flags = create_ce_flags(len, 0);
2107
ce->ce_mode = create_ce_mode(mode);
2108
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
2111
* We are not going to write this out, so this does not matter
2112
* right now, but someday we might optimize diff-index --cached
2113
* with cache-tree information.
2115
cache_tree_invalidate_path(active_cache_tree, path);
2117
commit->buffer = xmalloc(400);
2118
ident = fmt_ident("Not Committed Yet", "not.committed.yet", NULL, 0);
2119
snprintf(commit->buffer, 400,
2120
"tree 0000000000000000000000000000000000000000\n"
2124
"Version of %s from %s\n",
2125
sha1_to_hex(head_sha1),
2126
ident, ident, path, contents_from ? contents_from : path);
1629
2130
int cmd_blame(int argc, const char **argv, const char *prefix)
1631
2132
struct rev_info revs;
1649
2155
const char *arg = argv[i];
1650
2156
if (*arg != '-')
2158
else if (!strcmp("-b", arg))
2160
else if (!strcmp("--root", arg))
2162
else if (!strcmp(arg, "--show-stats"))
1652
2164
else if (!strcmp("-c", arg))
1653
2165
output_option |= OUTPUT_ANNOTATE_COMPAT;
1654
2166
else if (!strcmp("-t", arg))
1655
2167
output_option |= OUTPUT_RAW_TIMESTAMP;
1656
2168
else if (!strcmp("-l", arg))
1657
2169
output_option |= OUTPUT_LONG_OBJECT_NAME;
2170
else if (!strcmp("-s", arg))
2171
output_option |= OUTPUT_NO_AUTHOR;
2172
else if (!strcmp("-w", arg))
2173
xdl_opts |= XDF_IGNORE_WHITESPACE;
1658
2174
else if (!strcmp("-S", arg) && ++i < argc)
1659
2175
revs_file = argv[i];
1660
else if (!strncmp("-M", arg, 2)) {
2176
else if (!prefixcmp(arg, "-M")) {
1661
2177
opt |= PICKAXE_BLAME_MOVE;
1662
2178
blame_move_score = parse_score(arg+2);
1664
else if (!strncmp("-C", arg, 2)) {
2180
else if (!prefixcmp(arg, "-C")) {
2182
* -C enables copy from removed files;
2183
* -C -C enables copy from existing files, but only
2184
* when blaming a new file;
2185
* -C -C -C enables copy from existing files for
2188
if (opt & PICKAXE_BLAME_COPY_HARDER)
2189
opt |= PICKAXE_BLAME_COPY_HARDEST;
1665
2190
if (opt & PICKAXE_BLAME_COPY)
1666
2191
opt |= PICKAXE_BLAME_COPY_HARDER;
1667
2192
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
1668
2193
blame_copy_score = parse_score(arg+2);
1670
else if (!strncmp("-L", arg, 2)) {
2195
else if (!prefixcmp(arg, "-L")) {
1672
2197
if (++i >= argc)
1673
2198
usage(blame_usage);
1784
2320
if (final_commit_name)
1785
2321
argv[unk++] = final_commit_name;
1787
/* Now we got rev and path. We do not want the path pruning
2324
* Now we got rev and path. We do not want the path pruning
1788
2325
* but we may want "bottom" processing.
1790
2327
argv[unk++] = "--"; /* terminate the rev name */
1791
2328
argv[unk] = NULL;
1793
2330
init_revisions(&revs, NULL);
1794
setup_revisions(unk, argv, &revs, "HEAD");
2331
setup_revisions(unk, argv, &revs, NULL);
1795
2332
memset(&sb, 0, sizeof(sb));
1797
/* There must be one and only one positive commit in the
2335
* There must be one and only one positive commit in the
1798
2336
* revs->pending array.
1800
2338
for (i = 0; i < revs.pending.nr; i++) {
1817
2355
if (!sb.final) {
1818
/* "--not A B -- path" without anything positive */
1819
unsigned char head_sha1[20];
1821
final_commit_name = "HEAD";
1822
if (get_sha1(final_commit_name, head_sha1))
1823
die("No such ref: HEAD");
1824
sb.final = lookup_commit_reference(head_sha1);
1825
add_pending_object(&revs, &(sb.final->object), "HEAD");
2357
* "--not A B -- path" without anything positive;
2358
* do not default to HEAD, but use the working tree
2361
sb.final = fake_working_tree_commit(path, contents_from);
2362
add_pending_object(&revs, &(sb.final->object), ":");
2364
else if (contents_from)
2365
die("Cannot use --contents with final commit object name");
1828
/* If we have bottom, this will mark the ancestors of the
2368
* If we have bottom, this will mark the ancestors of the
1829
2369
* bottom commits we would reach while traversing as
1830
2370
* uninteresting.
1832
2372
prepare_revision_walk(&revs);
1834
o = get_origin(&sb, sb.final, path);
1835
if (fill_blob_sha1(o))
1836
die("no such path %s in %s", path, final_commit_name);
2374
if (is_null_sha1(sb.final->object.sha1)) {
2377
buf = xmalloc(o->file.size + 1);
2378
memcpy(buf, o->file.ptr, o->file.size + 1);
2380
sb.final_buf_size = o->file.size;
2383
o = get_origin(&sb, sb.final, path);
2384
if (fill_blob_sha1(o))
2385
die("no such path %s in %s", path, final_commit_name);
1838
sb.final_buf = read_sha1_file(o->blob_sha1, type, &sb.final_buf_size);
2387
sb.final_buf = read_sha1_file(o->blob_sha1, &type,
2388
&sb.final_buf_size);
2390
die("Cannot read blob %s for path %s",
2391
sha1_to_hex(o->blob_sha1),
1839
2394
num_read_blob++;
1840
2395
lno = prepare_lines(&sb);