当前位置: 首页 > news >正文

房地产十大营销手段seo零基础培训

房地产十大营销手段,seo零基础培训,齐鲁人才网招聘网,网站建设_网站设计_app制作​ 实现功能&#xff1a;借助jgit实现拉取文件&#xff0c;并返回文件路径清单 <!-- 依赖库 版本号有自行选择&#xff0c;只是需要注意支持的jdk版本即可&#xff0c;我使用的是jdk1.8--> <dependency><groupId>org.eclipse.jgit</groupId><artif…

​ 实现功能:借助jgit实现拉取文件,并返回文件路径清单

<!-- 依赖库 版本号有自行选择,只是需要注意支持的jdk版本即可,我使用的是jdk1.8-->
<dependency><groupId>org.eclipse.jgit</groupId><artifactId>org.eclipse.jgit</artifactId><version>5.13.2.202306221912-r</version>
</dependency>
// 还是用的 hutool和 lombok ,没有引入相关依赖的可以删除相关代码,使用类似代码替代。
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;@Slf4j
public class GitUtil {/*** 克隆git库.* @param url* @param localPath*/public static void cloneRepository(String url, String localPath) {try {Git git = Git.cloneRepository().setURI(url).setDirectory(new File(localPath)).call();Repository repository = git.getRepository();repository.close();log.info("Cloned repository successfully from {} to {}", url, localPath);} catch (GitAPIException e) {log.error("Failed to clone repository from {} to {}", url, localPath, e);} catch (Exception e) {log.error("Failed to clone repository from {} to {}", url, localPath, e);}}/*** 初始化本地git库.* @param localPath*/public static void initRepository(String localPath) {try {Git git = Git.init().setDirectory(new File(localPath)).call();Repository repository = git.getRepository();repository.close();log.info("Initialized repository successfully at {}", localPath);} catch (GitAPIException e) {log.error("Failed to initialize repository at {}", localPath, e);} catch (Exception e) {log.error("Failed to initialize repository at {}", localPath, e);}}/*** 添加* @param git*/public static void addAll(Git git) {try {git.add().addFilepattern(".").call();log.info("Added all files to staging area");} catch (GitAPIException e) {log.error("Failed to add all files to staging area", e);} catch (Exception e) {log.error("Failed to add all files to staging area", e);}}/*** 提交* @param git* @param message*/public static void commit(Git git, String message) {try {git.commit().setMessage(message).call();log.info("Committed changes with message: {}", message);} catch (GitAPIException e) {log.error("Failed to commit changes with message: {}", message, e);} catch (Exception e) {log.error("Failed to commit changes with message: {}", message, e);}}/*** 依据本地目录获取本地git库* @param localPath* @return*/public static Repository getRepository(String localPath) {FileRepositoryBuilder builder = new FileRepositoryBuilder();try {return builder.setGitDir(new File(localPath + "/.git")).readEnvironment().findGitDir().build();} catch (Exception e) {log.error("Failed to open repository at {}", localPath, e);return null;}}private static CanonicalTreeParser getTreeByObjectId(Git git, ObjectId objectId) throws Exception {try (ObjectReader reader = git.getRepository().newObjectReader();) {CanonicalTreeParser treeIter = new CanonicalTreeParser();treeIter.reset(reader, objectId);return treeIter;}}private static String getChangeType(DiffEntry diffEntry) {if (StrUtil.equals("/dev/null", diffEntry.getNewPath())) {return "del";}if (StrUtil.equals("/dev/null", diffEntry.getOldPath())) {return "add";}return "update";}private static void addDiifToMap(@NotNull Map<String, List<String>> changeInfoMap, @NotNull DiffEntry diffEntry) {String changeType = getChangeType(diffEntry);List<String> fileNameList = changeInfoMap.get(changeType);if (fileNameList == null) {changeInfoMap.put(changeType, new ArrayList<>());fileNameList = changeInfoMap.get(changeType);}fileNameList.add(StrUtil.equals("del", changeType) ? diffEntry.getOldPath() : diffEntry.getNewPath());}/*** 拉取文件并返回拉取的文件清单* @param repository* @return 返回 del(删除)、add(新增)、update(更新)的文件清单*/public static Map<String, List<String>> pull(Repository repository) {Map<String, List<String>> changeInfoMap = new HashMap<>();try (Git git = new Git(repository);) {// 1.拉取前记录当前的版本号.FetchResult fetchResult = git.fetch().call();ObjectId oldHead = git.getRepository().resolve("HEAD^{tree}");// 2.拉取并记录拉取后的版本号PullResult result = git.pull().call();ObjectId newHead = git.getRepository().resolve("HEAD^{tree}");// 3.计算差异清单。List<DiffEntry> diffs = git.diff().setNewTree(getTreeByObjectId(git, newHead)).setOldTree(getTreeByObjectId(git, oldHead)).call();for (DiffEntry entry : diffs) {addDiifToMap(changeInfoMap,entry);}} catch (GitAPIException e) {log.error("Failed to pull changes from remote repository", e);} catch (Exception e) {log.error("Failed to pull changes from remote repository", e);}return changeInfoMap;}
}

使用方式:

1.	在将代码库拉取到本地的目录中(也可以通过上面的代码,直接从远程仓库克隆到本地目录中)
2.	使用pull方法即可针对指定目录的git库进行拉取并返回拉取的文件清单,以做其他用处。

以上仅为案例,实际功能还需要配合其他逻辑实现。

http://www.ds6.com.cn/news/85664.html

相关文章:

  • 葫芦岛做网站公司网站seo的优化怎么做
  • php做旅游网站搜索引擎关键词seo优化公司
  • 公司找人做网站重庆森林经典台词 凤梨罐头
  • 网站建设企业公司推荐全媒体广告投放平台
  • 叫人做网站后不提供源码免费发帖的网站
  • 医程通 网站做的太网络销售真恶心
  • 第一次接推广多少钱合适沈阳seo关键词
  • 怎么做网站自动采集数据济南seo网络优化公司
  • 易优cms仿站教程百度推广优化师是什么
  • html网站设计论文万能优化大师下载
  • 只做动漫的网站百度竞价排名推广
  • 有关做服装的网站吗南宁seo计费管理
  • 做电商要注册网站吗附近的电脑培训班在哪里
  • 网站功能定制合同济南做网站公司哪家好
  • 哪里有服务好的网站建设公司百度排名优化工具
  • 自己做软件 做网站需要学会哪些怎么自己做一个小程序
  • 成都网站建设 推广行武汉seo学徒
  • 网页html模板代码优化设计官网
  • 网站开发攻略亚马逊关键词优化软件
  • 网站页面制作视频百度还原
  • doku做网站怎样打开网站
  • 学做网站开发吗百度产品推广
  • b2b免费信息发布平台惠州seo推广外包
  • 本地建网站的详细步骤东莞营销外包公司
  • 正规网站建设费用湖北短视频seo营销
  • 扬州市建筑信息平台许昌seo公司
  • 网站建设策划书正安县网站seo优化排名
  • 安徽专业做网站的公司长沙网络公司最新消息
  • 电商网站的模块女教师遭网课入侵直播录屏曝光i
  • 无锡做网站baidu百度搜索排名规则