[split-file] Default to --no-leading-lines

It turns out that the --leading-lines may be a bad default.
[[#@LINE+-num]] is rarely used.
This commit is contained in:
Fangrui Song 2021-08-16 19:23:11 -07:00
parent 5821047aac
commit 54e76cb17a
3 changed files with 12 additions and 8 deletions

View File

@ -1,5 +1,5 @@
# REQUIRES: x86 # REQUIRES: x86
# RUN: rm -rf %t && split-file %s %t # RUN: rm -rf %t && split-file --leading-lines %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o # RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
## There is no main linker script. OVERWRITE_SECTIONS defines output section ## There is no main linker script. OVERWRITE_SECTIONS defines output section

View File

@ -9,20 +9,20 @@ cc
//--- end //--- end
# RUN: rm -rf %t # RUN: rm -rf %t
# RUN: split-file %s %t # RUN: split-file --leading-lines %s %t
# RUN: diff %S/Inputs/basic-aa.txt %t/aa # RUN: diff %S/Inputs/basic-aa.txt %t/aa
# RUN: diff %S/Inputs/basic-bb.txt %t/bb # RUN: diff %S/Inputs/basic-bb.txt %t/bb
# RUN: diff %S/Inputs/basic-cc.txt %t/subdir/cc # RUN: diff %S/Inputs/basic-cc.txt %t/subdir/cc
# RUN: FileCheck %s --check-prefix=END < %t/end # RUN: FileCheck %s --check-prefix=END < %t/end
## Can be called on a non-empty directory. ## Can be called on a non-empty directory.
# RUN: split-file %s %t # RUN: split-file --leading-lines %s %t
# RUN: diff %S/Inputs/basic-aa.txt %t/aa # RUN: diff %S/Inputs/basic-aa.txt %t/aa
## Test that we will delete the output if it is a file, so that we can create ## Test that we will delete the output if it is a file, so that we can create
## a directory. ## a directory.
# RUN: rm -rf %t && touch %t # RUN: rm -rf %t && touch %t
# RUN: split-file %s %t # RUN: split-file --leading-lines %s %t
# RUN: diff %S/Inputs/basic-aa.txt %t/aa # RUN: diff %S/Inputs/basic-aa.txt %t/aa
# END: RUN: split-file %s %t # END: RUN: split-file %s %t

View File

@ -35,8 +35,12 @@ static cl::opt<std::string> input(cl::Positional, cl::desc("filename"),
static cl::opt<std::string> output(cl::Positional, cl::desc("directory"), static cl::opt<std::string> output(cl::Positional, cl::desc("directory"),
cl::value_desc("directory"), cl::cat(cat)); cl::value_desc("directory"), cl::cat(cat));
static cl::opt<bool> leadingLines("leading-lines",
cl::desc("Preserve line numbers"),
cl::cat(cat));
static cl::opt<bool> noLeadingLines("no-leading-lines", static cl::opt<bool> noLeadingLines("no-leading-lines",
cl::desc("Don't preserve line numbers"), cl::desc("Don't preserve line numbers (default)"),
cl::cat(cat)); cl::cat(cat));
static StringRef toolName; static StringRef toolName;
@ -96,9 +100,9 @@ static int handle(MemoryBuffer &inputBuf, StringRef input) {
Part &cur = res.first->second; Part &cur = res.first->second;
if (!i.is_at_eof()) if (!i.is_at_eof())
cur.begin = i->data(); cur.begin = i->data();
// If --no-leading-lines is not specified, numEmptyLines is 0. Append // If --leading-lines is specified, numEmptyLines is 0. Append newlines so
// newlines so that the extracted part preserves line numbers. // that the extracted part preserves line numbers.
cur.leadingLines = noLeadingLines ? 0 : i.line_number() - 1; cur.leadingLines = leadingLines ? i.line_number() - 1 : 0;
lastPart = partName; lastPart = partName;
} }