App-FuguBench

 view release on metacpan or  search on metacpan

lib/App/FuguBench/Wiki.pm  view on Meta::CPAN

#	its next push is a fast-forward and needs no retry. A branch
#	with a commit of its own stays, and the push loop rebases it.
#
#	A failed fetch warns. The count and the search then read the
#	ref of the last fetch, and a checkout without network access
#	is normal.
sub _fetch ( $app, $dir, $branch )
{
	unless (
		defined _git( $app, $dir, 'fetch', '--quiet', 'origin',
			$branch ) )
	{
		$app->cli->log->warning(
			'cannot fetch origin/%s, the count can be stale',
			$branch );
		return 0;
	}

	my $own =
	    _capture( $app, $dir, 'rev-list', '--count',
		"origin/$branch..HEAD" );
	_git( $app, $dir, 'merge', '--quiet', '--ff-only', "origin/$branch" )
	    if defined $own && $own eq '0';

	return 1;
}

# _origin_pages($app, $dir, $branch):
#	Each page of the fetched branch. The list is empty when no
#	fetch reached the origin, and the count is then local.
sub _origin_pages ( $app, $dir, $branch )
{
	return () unless defined $branch;

	my $out =
	    _capture( $app, $dir, 'ls-tree', '--name-only', "origin/$branch" );
	return () unless defined $out;

	return grep { /[.]md\z/ } split /\n/, $out;
}

# _origin_page_of_session($app, $dir, $branch, $session):
#	The page of the fetched branch that records one session, or
#	undef (WIKI-OPEN-1). An undefined branch gives undef, and a
#	branch without that page gives undef. A failed fetch leaves the
#	ref of the last fetch, and the search then reads it.
#
#	A clone that holds a commit of its own takes no fast-forward,
#	so its working tree can miss the page that the origin holds,
#	and open would give that session a second page (D-08). One git
#	grep reads the branch, because the library holds a page of
#	every session of every day. Of every call that this verb
#	parses, git colors the output of grep alone, so it carries
#	--no-color.
sub _origin_page_of_session ( $app, $dir, $branch, $session )
{
	return unless defined $branch;

	# The token holds letters, digits, a dot, a dash, and an
	# underscore (WIKI-OPEN-5). The dot is the one character that
	# the pattern of git reads, so the escape takes it alone.
	my $pattern = '^Session: ' . ( $session =~ s/[.]/\\./gr ) . '$';
	my $out     = _capture(
		$app,             $dir,
		'grep',           '--no-color',
		'--name-only',    '--extended-regexp',
		'-e',             $pattern,
		"origin/$branch", '--',
		'Session-*.md'
	);
	return unless defined $out && length $out;

	# One line of the output is <ref>:<page>, and the first match
	# answers.
	my $prefix = "origin/$branch:";
	my ($line) = split /\n/, $out;
	return unless rindex( $line, $prefix, 0 ) == 0;

	return substr $line, length $prefix;
}

# _resume($app, $dir, $branch, $session):
#	The page of the fetched branch that records one session,
#	brought into the working tree, or undef (WIKI-OPEN-2).
#
#	A clone that holds a commit of its own takes no fast-forward,
#	so the checkout gives it that page. note reads the file, and
#	close reads the Session: line of the file. A page of the
#	fetched branch alone serves neither one (WIKI-CAPTURE-1,
#	WIKI-CAPTURE-2).
#
#	The name comes from the tree of the origin, so it passes the
#	shape check before it reaches the filesystem and git
#	(CLI-PROGRAM-6). An invalid name and a failed checkout each
#	give undef, and open then opens a page.
sub _resume ( $app, $dir, $branch, $session )
{
	my $page = _origin_page_of_session( $app, $dir, $branch, $session )
	    or return;
	_page_path( $app, $dir, $page ) or return;

	unless (
		defined _git( $app, $dir, 'checkout', "origin/$branch", '--',
			$page ) )
	{
		$app->cli->log->error( 'cannot check out %s: %s',
			$page, $app->error );
		return;
	}

	return $page;
}

# _move($app, $dir, $page, $next, $title):
#	Rename the page of the commit, write the title of the new
#	index into it, and amend the commit with the new name
#	(WIKI-OPEN-3). The name and the title carry one index, so a
#	page of the old title would contradict its own name
#	(WIKI-PAGES-3).
#
#	The new name, or undef after a failure. The caller then reports



( run in 1.350 second using v1.01-cache-2.11-cpan-54e63673c56 )