<commit_before>#include "sccs.h"
#include "bkd.h"
#include "nested.h"

private	void	compat_status(int verbose, FILE *f);

int
status_main(int ac, char **av)
{
	int	i, c;
	int	compat = 0, verbose = 0;
	int	isnest;
	nested	*n;
	comp	*cp;
	int	ncomps = 0, nhere = 0;
	int	nmods = 0, npend = 0;
	char	*p;
	FILE	*fchg, *fsfile;
	char	**parents = 0;
	hash	*pcount;
	u32	bits;
	char	**attr = 0;
	struct item {
		int	cnt[2];
		char	*err;
	} *pi = 0;
	longopt	lopts[] = {
		{ "compat", 300 },
		{ 0, 0 }
		};

	putenv("PAGER=cat");
	while ((c = getopt(ac, av, "v", lopts)) != -1) {
		switch (c) {
		    case 'v': verbose++; break;			/* doc 2.0 */
		    case 300: // --compat
			compat++;
			break;
		    default: bk_badArg(c, av);
		}
	}
	if (av[optind]) {
		if (av[optind+1]) usage();
		if (chdir(av[optind])) {
			perror(av[optind]);
			return (1);
		}
	}
	if (compat) {
		compat_status(verbose, stdout);
		return (0);
	}
	/* 7.0 status starts here */
	isnest = bk_nested2root(0);

	/* start these early to reduce latency */
	fchg = popen("bk changes -aLR -nd. 2>&1", "r");
	fsfile = popen("bk -e sfiles -Ucgvhp", "r"); /* XXX no scancomps */

	printf("Repo: %s:%s\n", sccs_realhost(), proj_root(0));
	if (isnest) {
		n = nested_init(0, 0, 0, NESTED_PENDING);
		assert(n);
		EACH_STRUCT(n->comps, cp, i) {
			++ncomps;
			if (C_PRESENT(cp)) ++nhere;
		}
		nested_free(n);
		printf("Nested repo: %d/%d components present\n",
		    nhere, ncomps);
	}

	/* per-parent information */
	pcount = hash_new(HASH_MEMHASH);
	pcount->vptr = 0;
	c = 0;		/* for compiler */
	while (p = fgetline(fchg)) {
		if (strneq(p, "==== changes -", 14)) {<commit_msg>Prevent assert when bk status --compat -v is run outside a repository.<commit_after>#include "sccs.h"
#include "bkd.h"
#include "nested.h"

private	void	compat_status(int verbose, FILE *f);

int
status_main(int ac, char **av)
{
	int	i, c;
	int	compat = 0, verbose = 0;
	int	isnest;
	nested	*n;
	comp	*cp;
	int	ncomps = 0, nhere = 0;
	int	nmods = 0, npend = 0;
	char	*p;
	FILE	*fchg, *fsfile;
	char	**parents = 0;
	hash	*pcount;
	u32	bits;
	char	**attr = 0;
	struct item {
		int	cnt[2];
		char	*err;
	} *pi = 0;
	longopt	lopts[] = {
		{ "compat", 300 },
		{ 0, 0 }
		};

	putenv("PAGER=cat");
	while ((c = getopt(ac, av, "v", lopts)) != -1) {
		switch (c) {
		    case 'v': verbose++; break;			/* doc 2.0 */
		    case 300: // --compat
			compat++;
			break;
		    default: bk_badArg(c, av);
		}
	}
	if (av[optind]) {
		if (av[optind+1]) usage();
		if (chdir(av[optind])) {
			perror(av[optind]);
			return (1);
		}
	}

	isnest = bk_nested2root(0);
	if (compat) {
		compat_status(verbose, stdout);
		return (0);
	}

	/* 7.0 status starts here */
	/* start these early to reduce latency */
	fchg = popen("bk changes -aLR -nd. 2>&1", "r");
	fsfile = popen("bk -e sfiles -Ucgvhp", "r"); /* XXX no scancomps */

	printf("Repo: %s:%s\n", sccs_realhost(), proj_root(0));
	if (isnest) {
		n = nested_init(0, 0, 0, NESTED_PENDING);
		assert(n);
		EACH_STRUCT(n->comps, cp, i) {
			++ncomps;
			if (C_PRESENT(cp)) ++nhere;
		}
		nested_free(n);
		printf("Nested repo: %d/%d components present\n",
		    nhere, ncomps);
	}

	/* per-parent information */
	pcount = hash_new(HASH_MEMHASH);
	pcount->vptr = 0;
	c = 0;		/* for compiler */
	while (p = fgetline(fchg)) {
		if (strneq(p, "==== changes -", 14)) {
{'fraction_non_alphanumeric': 0.1963963963963964, 'fraction_numerical': 0.024024024024024024, 'mean_word_length': 3.077111383108935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6665372', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1491, 'n_words': 375}