<commit_before>package br.ufmg.dcc.labsoft.apidiff.detect.diff.service.git;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.RevWalkUtils;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.ufmg.dcc.labsoft.apidiff.UtilTools;

public class GitServiceImpl implements GitService {
	
	private static final String REMOTE_REFS_PREFIX = "refs/remotes/origin/";
	
	private DefaultCommitsFilter commitsFilter = new DefaultCommitsFilter();
	
	private Logger logger = LoggerFactory.getLogger(GitServiceImpl.class);
	
	private static final Long MINUTE = 60000L; //60.000 miliseconds
	private static final Long HOUR = MINUTE * 60;
	private static final Long DAY = HOUR * 24;
	private static final Long SEVEN_DAYS = DAY * 7; //7 dias em milissegundos.
	
	private class DefaultCommitsFilter extends RevFilter {
		@Override
		public final boolean include(final RevWalk walker, final RevCommit c) {
			//Se c.getParentCount() > 1, temos um merge de branches. 
			Long diffTimestamp = 0L;
			if(c.getParentCount() > 1){
				logger.info("Merge branches deleted. [commitId="+c.getId().getName()+"]");
			}
			else{//Se é um commit muito velho (mais de 7 dias)
				Calendar timeNow = Calendar.getInstance();
				Long timestampNow = timeNow.getTimeInMillis();
				
				Long timestampCommit = (long)c.getCommitTime() * 1000;
				Calendar calendarCommit = Calendar.getInstance();
				calendarCommit.setTime(new Date(timestampCommit));
				
				diffTimestamp = Math.abs(timestampCommit - timestampNow);
						
				//Apenas commits realizados a no máximo 1 semana.
				if(diffTimestamp > SEVEN_DAYS){
					SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
					String formattedDateCommit = format.format(calendarCommit.getTime());
					logger.info("Commit old deleted. [commitId="+c.getId().getName()+"][date="+formattedDateCommit+"]");
				}
			}
			
			return ((c.getParentCount() == 1 && !isCommitAnalyzed(c.getName())) || (diffTimestamp > SEVEN_DAYS));
		}

		@Override
		public final RevFilter clone() {
			return this;
		}
<commit_msg>APIDIff-43 Correção da regra para eliminar commits antigos.<commit_after>package br.ufmg.dcc.labsoft.apidiff.detect.diff.service.git;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.RevWalkUtils;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.ufmg.dcc.labsoft.apidiff.UtilTools;

public class GitServiceImpl implements GitService {
	
	private static final String REMOTE_REFS_PREFIX = "refs/remotes/origin/";
	
	private DefaultCommitsFilter commitsFilter = new DefaultCommitsFilter();
	
	private Logger logger = LoggerFactory.getLogger(GitServiceImpl.class);
	
	private static final Long MINUTE = 60000L; //60.000 miliseconds
	private static final Long HOUR = MINUTE * 60;
	private static final Long DAY = HOUR * 24;
	private static final Long SEVEN_DAYS = DAY * 7; //7 dias em milissegundos.
	
	private class DefaultCommitsFilter extends RevFilter {
		@Override
		public final boolean include(final RevWalk walker, final RevCommit c) {
			//Se c.getParentCount() > 1, temos um merge de branches. 
			Long diffTimestamp = 0L;
			if(c.getParentCount() > 1){
				logger.info("Merge branches deleted. [commitId="+c.getId().getName()+"]");
			}
			//Se é um commit muito velho (mais de 7 dias)
			Calendar timeNow = Calendar.getInstance();
			Long timestampNow = timeNow.getTimeInMillis();
			
			Long timestampCommit = (long)c.getCommitTime() * 1000;
			Calendar calendarCommit = Calendar.getInstance();
			calendarCommit.setTime(new Date(timestampCommit));
			
			diffTimestamp = Math.abs(timestampCommit - timestampNow);
					
			//Apenas commits realizados a no máximo 1 semana.
			if(diffTimestamp > SEVEN_DAYS){
				SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
				String formattedDateCommit = format.format(calendarCommit.getTime());
				logger.info("Commit old deleted. [commitId="+c.getId().getName()+"][date="+formattedDateCommit+"]");
			}
			
			
			return ((c.getParentCount() == 1) && (!isCommitAnalyzed(c.getName())) && (diffTimestamp <= SEVEN_DAYS));
		}

		@Override
		public final RevFilter clone() {
			return this;
		}

{'fraction_non_alphanumeric': 0.11463994565217392, 'fraction_numerical': 0.00985054347826087, 'mean_word_length': 4.678881388621022, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, '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': '1120393', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1864, 'n_words': 419}