Skip to content

Commit d2fbd3d

Browse files
committed
Update: Added breadth mode
1 parent f3a8fee commit d2fbd3d

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

source/redub/buildapi.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import redub.package_searching.api;
88

99

1010
///vX.X.X
11-
enum RedubVersionOnly = "v1.21.2";
11+
enum RedubVersionOnly = "v1.21.3";
1212
///Redub vX.X.X
1313
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1414
///Redub vX.X.X - Description

source/redub/command_generators/commons.d

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,54 @@ private __gshared bool usingBreadth;
338338
void setSpanModeAsBreadth(bool breadth)
339339
{
340340
import core.atomic;
341-
atomicStore(breadth, true);
341+
import redub.logging;
342+
warn("Using redub search file mode as breadth for dub compatibility.");
343+
atomicStore(usingBreadth, true);
344+
}
345+
346+
auto dirEntriesBreadth(string inputPath)
347+
{
348+
import std.file;
349+
import std.array;
350+
struct DirEntriesRange
351+
{
352+
DirEntry[] currPathEntries;
353+
DirEntry[] nextDirs;
354+
355+
void popFront()
356+
{
357+
if(currPathEntries.length == 0)
358+
{
359+
if(nextDirs.length == 0)
360+
return;
361+
362+
while(nextDirs.length && currPathEntries.length == 0)
363+
{
364+
DirEntry next = nextDirs[0];
365+
currPathEntries = dirEntries(next.name, SpanMode.shallow).array;
366+
nextDirs = nextDirs[1..$];
367+
}
368+
}
369+
else
370+
{
371+
if(currPathEntries[0].isDir)
372+
nextDirs~= currPathEntries[0];
373+
currPathEntries = currPathEntries[1..$];
374+
}
375+
376+
377+
}
378+
bool empty(){return currPathEntries.length == 0 && nextDirs.length == 0;}
379+
DirEntry front()
380+
{
381+
if(currPathEntries.length == 0)
382+
popFront();
383+
return currPathEntries[0];
384+
}
385+
}
386+
387+
388+
return DirEntriesRange(dirEntries(inputPath, SpanMode.shallow).array);
342389
}
343390

344391
void putSourceFiles(
@@ -356,24 +403,46 @@ void putSourceFiles(
356403
import std.algorithm.searching;
357404
import std.exception;
358405
import std.array;
406+
import std.range:choose;
359407
import core.atomic;
360408

361409
auto app = appender!(string[]);
362410
scope(exit)
363411
{
364412
output~= app.data;
365413
}
366-
367-
foreach(path; paths)
414+
415+
if(atomicLoad(usingBreadth))
368416
{
369-
DirEntryLoop: foreach(DirEntry e; dirEntries(unescapePath(path), atomicLoad(usingBreadth) ? SpanMode.breadth : SpanMode.depth))
417+
foreach(path; paths)
418+
DirEntryLoopBreadth: foreach(DirEntry e; dirEntriesBreadth(unescapePath(path)))
370419
{
371420
foreach(exclusion; excludeFiles)
372421
if(e.name.globMatch(exclusion))
373-
continue DirEntryLoop;
422+
continue DirEntryLoopBreadth;
423+
if(isFileHidden(e) || e.isDir)
424+
continue;
425+
foreach(ext; extensions)
426+
{
427+
if(e.name.endsWith(ext))
428+
{
429+
app~= escapePath(e.name);
430+
break;
431+
}
432+
}
433+
}
434+
}
435+
else
436+
{
437+
foreach(path; paths)
438+
DirEntryLoopDepth: foreach(DirEntry e; dirEntries(unescapePath(path),SpanMode.depth))
439+
{
440+
foreach(exclusion; excludeFiles)
441+
if(e.name.globMatch(exclusion))
442+
continue DirEntryLoopDepth;
374443
if(isFileHidden(e) || e.isDir)
375444
continue;
376-
foreach(ext; extensions)
445+
foreach(ext; extensions)
377446
{
378447
if(e.name.endsWith(ext))
379448
{
@@ -383,6 +452,7 @@ void putSourceFiles(
383452
}
384453
}
385454
}
455+
386456
foreach(i, file; files)
387457
{
388458
if(output.countUntil(file) != -1)

0 commit comments

Comments
 (0)