Skip to content

Commit b3c46f8

Browse files
committed
Support mnemonic diff format
- Support [iwco]/ path prefix. Example: $ git -c diff.mnemonicprefix=true diff HEAD~1 | showlinenum.awk show_path=1 diff --git c/calc.exe w/calc.exe new file mode 100644 index 0000000..aaa2f16 Binary files /dev/null and w/calc.exe differ calc.exe:: Prior to this change only [ab]/ path prefix was supported and a fatal error would occur otherwise. Fixes jay#4
1 parent b3308c1 commit b3c46f8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

showlinenum.awk

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ function fix_extracted_path(input)
274274
return input;
275275
}
276276

277-
if(input !~ /^\042?[ab]\//)
277+
if(input !~ /^\042?[abiwco]\//)
278278
{
279-
errmsg = "fix_extracted_path(): sanity check failed, expected a/ or b/ " \
279+
errmsg = "fix_extracted_path(): sanity check failed, expected [abiwco]/ " \
280280
"prefix." \
281281
"\n" "Path: " input;
282282
FATAL(errmsg);
@@ -301,15 +301,15 @@ function fix_extracted_path(input)
301301
}
302302

303303
# Remove an erroneous trailing tab that git diff can add to some non-binary
304-
# paths. eg an unquoted 'b/a $b ' becomes 'b/a $b' if the diff line only
305-
# contains the latter.
304+
# paths. eg an unquoted 'b/a $b ' becomes 'b/a $b' if the diff line
305+
# only contains the latter.
306306
if((input ~ /\t$/) && !index(diff, input) && \
307307
index(diff, substr(input, 1, length(input) - 1)))
308308
{
309309
sub(/\t$/, "", input);
310310
}
311311

312-
sub(/[ab]\//, "", input);
312+
sub(/[abiwco]\//, "", input);
313313

314314
return input;
315315
}
@@ -464,7 +464,7 @@ function print_path(a_path)
464464
stripped = strip_ansi_color_codes($0);
465465

466466
# Check for oldfile path
467-
regex = "^\\-\\-\\- (\\042?a\\/.+|\\/dev\\/null)$";
467+
regex = "^\\-\\-\\- (\\042?[aiwco]\\/.+|\\/dev\\/null)$";
468468
if(stripped ~ regex)
469469
{
470470
oldfile_path = fix_extracted_path(gensub(regex, "\\1", 1, stripped));
@@ -479,7 +479,7 @@ function print_path(a_path)
479479
}
480480

481481
# Check for newfile path
482-
regex = "^\\+\\+\\+ (\\042?b\\/.+|\\/dev\\/null)$";
482+
regex = "^\\+\\+\\+ (\\042?[biwco]\\/.+|\\/dev\\/null)$";
483483
if(stripped ~ regex)
484484
{
485485
path = fix_extracted_path(gensub(regex, "\\1", 1, stripped));
@@ -509,7 +509,7 @@ function print_path(a_path)
509509
{
510510
oldfile_path = substr(path, 1, length(path) - RLENGTH);
511511

512-
if((oldfile_path ~ /^\042?a\//) && index(diff, oldfile_path))
512+
if((oldfile_path ~ /^\042?[aiwco]\//) && index(diff, oldfile_path))
513513
{
514514
oldfile_path = fix_extracted_path(oldfile_path);
515515
found_oldfile_path = 1;
@@ -521,7 +521,7 @@ function print_path(a_path)
521521
# This gets the path for a binary file by digging through the first line
522522
# of the diff header ('diff') and the binary file notice line
523523
# ('stripped') to find the longest rightmost match between the two.
524-
while(!found_path && match(path, /and \042?b\/.+$/))
524+
while(!found_path && match(path, /and \042?[biwco]\/.+$/))
525525
{
526526
path_len = RLENGTH - 4;
527527
path = substr(path, RSTART + 4, path_len);

0 commit comments

Comments
 (0)