/** * Check if this sub repo is the ancestor of given sub repo. * * @param that * non null * @return true if this sub repo is the ancestor of given sub repo. */ public boolean isAncestorOf(RepoProject that) { return isAncestorOf(that.getPathWithSlash()); }
private void removeNestedCopyAndLinkfiles() { for (RepoProject proj : filteredProjects) { List<CopyFile> copyfiles = new ArrayList<>(proj.getCopyFiles()); proj.clearCopyFiles(); for (CopyFile copyfile : copyfiles) { if (!isNestedReferencefile(copyfile)) { proj.addCopyFile(copyfile); } } List<LinkFile> linkfiles = new ArrayList<>(proj.getLinkFiles()); proj.clearLinkFiles(); for (LinkFile linkfile : linkfiles) { if (!isNestedReferencefile(linkfile)) { proj.addLinkFile(linkfile); } } } }
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (o instanceof RepoProject) { RepoProject that = (RepoProject) o; return this.getPathWithSlash().equals(that.getPathWithSlash()); } return false; }
checkCallable(); if (baseUri == null) { baseUri = ""; //$NON-NLS-1$ ManifestParser parser = new ManifestParser(includedReader, manifestPath, branch, baseUri, groupsParam, repo); parser.read(inputStream); filteredProjects = parser.getFilteredProjects(); } catch (IOException e) { throw new ManifestErrorException(e); } finally { try { author = new PersonIdent(repo); if (callback == null) callback = new DefaultRemoteReader(); List<RepoProject> renamedProjects = renameProjects(filteredProjects); StringBuilder attributes = new StringBuilder(); for (RepoProject proj : renamedProjects) { String name = proj.getName(); String path = proj.getPath(); String url = proj.getUrl(); ObjectId objectId; if (ObjectId.isId(proj.getRevision())) { objectId = ObjectId.fromString(proj.getRevision()); } else { objectId = callback.sha1(url, proj.getRevision()); if (objectId == null && !ignoreRemoteFailures) {
if ("project".equals(qName)) { //$NON-NLS-1$ if (attributes.getValue("name") == null) { //$NON-NLS-1$ throw new SAXException(RepoText.get().invalidManifest); currentProject = new RepoProject( attributes.getValue("name"), //$NON-NLS-1$ attributes.getValue("path"), //$NON-NLS-1$ attributes.getValue("remote"), //$NON-NLS-1$ attributes.getValue("groups")); //$NON-NLS-1$ currentProject.setRecommendShallow( attributes.getValue("clone-depth")); //$NON-NLS-1$ } else if ("remote".equals(qName)) { //$NON-NLS-1$ String fetch = attributes.getValue("fetch"); //$NON-NLS-1$ String revision = attributes.getValue("revision"); //$NON-NLS-1$ Remote remote = new Remote(fetch, revision); remotes.put(attributes.getValue("name"), remote); //$NON-NLS-1$ if (alias != null) } else if ("copyfile".equals(qName)) { //$NON-NLS-1$ if (currentProject == null) throw new SAXException(RepoText.get().invalidManifest); currentProject.addCopyFile(new CopyFile( rootRepo, currentProject.getPath(), attributes.getValue("src"), //$NON-NLS-1$ attributes.getValue("dest"))); //$NON-NLS-1$ } else if ("linkfile".equals(qName)) { //$NON-NLS-1$
Map<String, List<RepoProject>> m = new TreeMap<>(); for (RepoProject proj : projects) { List<RepoProject> l = m.get(proj.getName()); if (l == null) { l = new ArrayList<>(); m.put(proj.getName(), l); boolean nameConflict = ps.size() != 1; for (RepoProject proj : ps) { String name = proj.getName(); if (nameConflict) { name += SLASH + proj.getPath(); RepoProject p = new RepoProject(name, proj.getPath(), proj.getRevision(), null, proj.getGroups(), proj.getRecommendShallow()); p.setUrl(proj.getUrl()); p.addCopyFiles(proj.getCopyFiles()); p.addLinkFiles(proj.getLinkFiles()); ret.add(p);
String remote = proj.getRemote(); String revision = defaultRevision; if (remote == null) { if (filename != null) throw new SAXException(MessageFormat.format( RepoText.get().errorNoDefaultFilename, filename)); else throw new SAXException( RepoText.get().errorNoDefault); if (fetch == null) { throw new SAXException(MessageFormat .format(RepoText.get().errorNoFetch, remote)); remoteUrl = normalizeEmptyPath(baseUrl.resolve(fetch)); remoteUrls.put(remote, remoteUrl); proj.setUrl(remoteUrl.resolve(proj.getName()).toString()) .setDefaultRevision(revision); removeNotInGroup(); removeOverlaps();
private boolean isNestedReferencefile(ReferenceFile referencefile) { if (referencefile.dest.indexOf('/') == -1) { // If the referencefile is at root level then it won't be nested. return false; } for (RepoProject proj : filteredProjects) { if (proj.getPath().compareTo(referencefile.dest) > 0) { // Early return as remaining projects can't be ancestor of this // referencefile config (filteredProjects is sorted). return false; } if (proj.isAncestorOf(referencefile.dest)) { return true; } } return false; }
/** Remove projects that sits in a subdirectory of any other project. */ void removeOverlaps() { Collections.sort(filteredProjects); Iterator<RepoProject> iter = filteredProjects.iterator(); if (!iter.hasNext()) return; RepoProject last = iter.next(); while (iter.hasNext()) { RepoProject p = iter.next(); if (last.isAncestorOf(p)) iter.remove(); else last = p; } removeNestedCopyAndLinkfiles(); }
private void addSubmodule(String name, String url, String path, String revision, List<CopyFile> copyfiles, List<LinkFile> linkfiles, Git git) throws GitAPIException, IOException { assert (!repo.isBare()); assert (git != null); if (!linkfiles.isEmpty()) { throw new UnsupportedOperationException( JGitText.get().nonBareLinkFilesNotSupported); } SubmoduleAddCommand add = git.submoduleAdd().setName(name).setPath(path) .setURI(url); if (monitor != null) add.setProgressMonitor(monitor); Repository subRepo = add.call(); if (revision != null) { try (Git sub = new Git(subRepo)) { sub.checkout().setName(findRef(revision, subRepo)).call(); } subRepo.close(); git.add().addFilepattern(path).call(); } for (CopyFile copyfile : copyfiles) { copyfile.copy(); git.add().addFilepattern(copyfile.dest).call(); } }
/** * Read a file from a remote repository. * * @param uri * The URI of the remote repository * @param ref * The ref (branch/tag/etc.) to read * @param path * The relative path (inside the repo) to the file to read * @return the file content. * @throws GitAPIException * @throws IOException * @since 3.5 * * @deprecated Use {@link #readFileWithMode(String, String, String)} * instead */ @Deprecated public default byte[] readFile(String uri, String ref, String path) throws GitAPIException, IOException { return readFileWithMode(uri, ref, path).getContents(); }
@Override public RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) .setURI(uri).call()) { Repository repo = git.getRepository(); ObjectId refCommitId = sha1(uri, ref); if (refCommitId == null) { throw new InvalidRefNameException(MessageFormat .format(JGitText.get().refNotResolved, ref)); } RevCommit commit = repo.parseCommit(refCommitId); TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree()); // TODO(ifrade): Cope better with big files (e.g. using // InputStream instead of byte[]) return new RemoteFile( tw.getObjectReader().open(tw.getObjectId(0)) .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0)); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } } }
boolean inGroups(RepoProject proj) { for (String group : minusGroups) { if (proj.inGroup(group)) { // minus groups have highest priority. return false; } } if (plusGroups.isEmpty() || plusGroups.contains("all")) { //$NON-NLS-1$ // empty plus groups means "all" return true; } for (String group : plusGroups) { if (proj.inGroup(group)) return true; } return false; }
/** Remove projects that are not in our desired groups. */ void removeNotInGroup() { Iterator<RepoProject> iter = filteredProjects.iterator(); while (iter.hasNext()) if (!inGroups(iter.next())) iter.remove(); }
/** * Constructor for RepoProject * * @param name * the relative path to the {@code remote} * @param path * the relative path to the super project * @param revision * a SHA-1 or branch name or tag name * @param remote * name of the remote definition * @param groupsParam * comma separated group list */ public RepoProject(String name, String path, String revision, String remote, String groupsParam) { this(name, path, revision, remote, new HashSet<String>(), null); if (groupsParam != null && groupsParam.length() > 0) this.setGroups(groupsParam); }
this.defaultBranch = defaultBranch; this.rootRepo = rootRepo; this.baseUrl = normalizeEmptyPath(URI.create(baseUrl));
/** * Check if this sub repo is the ancestor of given sub repo. * * @param that * non null * @return true if this sub repo is the ancestor of given sub repo. */ public boolean isAncestorOf(RepoProject that) { return isAncestorOf(that.getPathWithSlash()); }
/** {@inheritDoc} */ @Override public int compareTo(RepoProject that) { return this.getPathWithSlash().compareTo(that.getPathWithSlash()); } }
/** * Check if this sub repo is an ancestor of the given path. * * @param thatPath * path to be checked to see if it is within this repository * @return true if this sub repo is an ancestor of the given path. * @since 4.2 */ public boolean isAncestorOf(String thatPath) { return thatPath.startsWith(getPathWithSlash()); }
/** {@inheritDoc} */ @Override public int hashCode() { return this.getPathWithSlash().hashCode(); }