diff options
author | Ivan Frade <ifrade@google.com> | 2021-11-23 14:42:01 -0800 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2022-01-31 14:51:23 -0800 |
commit | dba66dbfce4dfa173ab884ba2d5c0bdf5f1b219c (patch) | |
tree | 41816ab9a8de2586be6476f3170f8a9df80e4ffa /org.eclipse.jgit | |
parent | dee4240ce86f21d262ac071ed80838223bf4d516 (diff) | |
download | jgit-dba66dbfce4dfa173ab884ba2d5c0bdf5f1b219c.tar.gz jgit-dba66dbfce4dfa173ab884ba2d5c0bdf5f1b219c.zip |
RepoCommand: Offer to set extra files in the destination repository
We want to save in the destination repository what manifest created its
structure. This helps to detect and debug failures in the manifest ->
superproject translations. The src commit should be easily readable from
the superproject tip.
Offer an API to write a file in the destination repository. RepoCommand
callers (e.g. gerrit supermanifest plugin) can use this to add a
file with the repo/ref/hash of the manifest.
Alternatives considered to write the source repo/ref/hash:
* .gitattributes of the .gitmodules file. Some updates in the manifest
don't touch the .gitmodules (e.g. a linkfile change), so it can fall
out of sync.
* commit message. Caller would need to follow the commit history to
find the latest modification by repo command. This is not helpful
e.g. for build bots that want to get the value in one call.
Change-Id: I113662734a7ccd39cbc60b46ad3f73038c807682
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/BareSuperprojectWriter.java | 27 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java | 22 |
2 files changed, 46 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/BareSuperprojectWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/BareSuperprojectWriter.java index d6482968fe..e6626aece3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/BareSuperprojectWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/BareSuperprojectWriter.java @@ -71,6 +71,8 @@ class BareSuperprojectWriter { private final PersonIdent author; + private List<ExtraContent> extraContents; + static class BareWriterConfig { boolean ignoreRemoteFailures = false; @@ -88,10 +90,22 @@ class BareSuperprojectWriter { } } + static class ExtraContent { + final String path; + + final String content; + + ExtraContent(String path, String content) { + this.path = path; + this.content = content; + } + } + BareSuperprojectWriter(Repository repo, URI targetUri, String targetBranch, PersonIdent author, RemoteReader callback, - BareWriterConfig config) { + BareWriterConfig config, + List<ExtraContent> extraContents) { assert (repo.isBare()); this.repo = repo; this.targetUri = targetUri; @@ -99,6 +113,7 @@ class BareSuperprojectWriter { this.author = author; this.callback = callback; this.config = config; + this.extraContents = extraContents; } RevCommit write(List<RepoProject> repoProjects) @@ -244,6 +259,16 @@ class BareSuperprojectWriter { builder.add(dcEntryAttr); } + for (ExtraContent ec : extraContents) { + DirCacheEntry extraDcEntry = new DirCacheEntry(ec.path); + + ObjectId oid = inserter.insert(Constants.OBJ_BLOB, + ec.content.getBytes(UTF_8)); + extraDcEntry.setObjectId(oid); + extraDcEntry.setFileMode(FileMode.REGULAR_FILE); + builder.add(extraDcEntry); + } + builder.finish(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 30b8626730..6e943e5d36 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -28,6 +28,7 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.GitCommand; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRefNameException; +import org.eclipse.jgit.gitrepo.BareSuperprojectWriter.ExtraContent; import org.eclipse.jgit.gitrepo.ManifestParser.IncludedFileReader; import org.eclipse.jgit.gitrepo.internal.RepoText; import org.eclipse.jgit.internal.JGitText; @@ -79,6 +80,8 @@ public class RepoCommand extends GitCommand<RevCommit> { private ProgressMonitor monitor; + private final List<ExtraContent> extraContents = new ArrayList<>(); + /** * A callback to get ref sha1 of a repository from its uri. * @@ -509,6 +512,22 @@ public class RepoCommand extends GitCommand<RevCommit> { return this; } + /** + * Create a file with the given content in the destination repository + * + * @param path + * where to create the file in the destination repository + * @param contents + * content for the create file + * @return this command + * + * @since 6.1 + */ + public RepoCommand addToDestination(String path, String contents) { + this.extraContents.add(new ExtraContent(path, contents)); + return this; + } + /** {@inheritDoc} */ @Override public RevCommit call() throws GitAPIException { @@ -550,7 +569,7 @@ public class RepoCommand extends GitCommand<RevCommit> { targetBranch, author == null ? new PersonIdent(repo) : author, callback == null ? new DefaultRemoteReader() : callback, - bareWriterConfig); + bareWriterConfig, extraContents); return writer.write(renamedProjects); } @@ -663,5 +682,4 @@ public class RepoCommand extends GitCommand<RevCommit> { return URI.create(j.toString()); } - } |