<commit_before>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  This file is part of Logtalk <https://logtalk.org/>
%  Copyright 1998-2021 <NAME> <<EMAIL>>
%  SPDX-License-Identifier: Apache-2.0
%
%  Licensed under the Apache License, Version 2.0 (the "License");
%  you may not use this file except in compliance with the License.
%  You may obtain a copy of the License at
%
%      http://www.apache.org/licenses/LICENSE-2.0
%
%  Unless required by applicable law or agreed to in writing, software
%  distributed under the License is distributed on an "AS IS" BASIS,
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%  See the License for the specific language governing permissions and
%  limitations under the License.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


:- object(git,
	implements(git_protocol)).

	:- info([
		version is 1:3:0,
		author is '<NAME>',
		date is 2021-07-22,
		comment is 'Predicates for accessing a git project current branch and latest commit data.'
	]).

	:- uses(os, [
		change_directory/1, delete_file/1, internal_os_path/2,
		path_concat/3, pid/1, temporary_directory/1, shell/1
	]).

	:- if(os::operating_system_type(windows)).

		branch(Directory, Branch) :-
			temporary_file(Temporary),
			internal_os_path(Temporary, NativeTemporary),
			atom_concat('git -C ', Directory, Command0),
			atom_concat(Command0, ' rev-parse --abbrev-ref HEAD 2>nul > ', Command1),
			atom_concat(Command1, NativeTemporary, Command),
			(	shell(Command) ->
				data_clean(Temporary, Branch),
				Branch \== ''
			;	delete_file(Temporary),
				fail
			).

		commit_log(Directory, Format, Output) :-
			temporary_file(Temporary),
			internal_os_path(Temporary, NativeTemporary),
			atom_concat('git -C ', NativeTemporary, Command0),
			atom_concat(Command0, ' log --oneline -n 1 --pretty=format:"', Command1),
			atom_concat(Command1, Format, Command2),
			atom_concat(Command2, '" 2>nul > ', Command3),
			atom_concat(Command3, NativeTemporary, Command),
			(	shell(Command) ->
				data_raw(Temporary, Output)
			;	delete_file(Temporary),<commit_msg>Fix typo in previous commit in the `git` library object<commit_after>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  This file is part of Logtalk <https://logtalk.org/>
%  Copyright 1998-2021 <NAME> <<EMAIL>>
%  SPDX-License-Identifier: Apache-2.0
%
%  Licensed under the Apache License, Version 2.0 (the "License");
%  you may not use this file except in compliance with the License.
%  You may obtain a copy of the License at
%
%      http://www.apache.org/licenses/LICENSE-2.0
%
%  Unless required by applicable law or agreed to in writing, software
%  distributed under the License is distributed on an "AS IS" BASIS,
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%  See the License for the specific language governing permissions and
%  limitations under the License.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


:- object(git,
	implements(git_protocol)).

	:- info([
		version is 1:3:0,
		author is '<NAME>',
		date is 2021-07-22,
		comment is 'Predicates for accessing a git project current branch and latest commit data.'
	]).

	:- uses(os, [
		change_directory/1, delete_file/1, internal_os_path/2,
		path_concat/3, pid/1, temporary_directory/1, shell/1
	]).

	:- if(os::operating_system_type(windows)).

		branch(Directory, Branch) :-
			temporary_file(Temporary),
			internal_os_path(Temporary, NativeTemporary),
			atom_concat('git -C ', Directory, Command0),
			atom_concat(Command0, ' rev-parse --abbrev-ref HEAD 2>nul > ', Command1),
			atom_concat(Command1, NativeTemporary, Command),
			(	shell(Command) ->
				data_clean(Temporary, Branch),
				Branch \== ''
			;	delete_file(Temporary),
				fail
			).

		commit_log(Directory, Format, Output) :-
			temporary_file(Temporary),
			internal_os_path(Temporary, NativeTemporary),
			atom_concat('git -C ', Directory, Command0),
			atom_concat(Command0, ' log --oneline -n 1 --pretty=format:"', Command1),
			atom_concat(Command1, Format, Command2),
			atom_concat(Command2, '" 2>nul > ', Command3),
			atom_concat(Command3, NativeTemporary, Command),
			(	shell(Command) ->
				data_raw(Temporary, Output)
			;	delete_file(Temporary),
{'fraction_non_alphanumeric': 0.18319559228650137, 'fraction_numerical': 0.02157943067033976, 'mean_word_length': 4.473618090452261, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5174279', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1318, 'n_words': 370}