Skip to content

Commit 4a3cbe2

Browse files
committed
Automatically stage transport version state files
Transport version state files should be managed by the relevant gradle tasks. After running these tasks, developers should not need to worry about which files they need to add to their commit. This commit makes every update to transport state files automatically stage the change in git.
1 parent 1f724bc commit 4a3cbe2

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/AbstractGenerateTransportVersionDefinitionTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void resetUpperBound(
159159
resetValue = idsForUpperBound.get(idsForUpperBound.size() - 2);
160160
}
161161
var resetUpperBound = new TransportVersionUpperBound(upperBound.name(), resetValue.definition().name(), resetValue.id());
162-
resources.writeUpperBound(resetUpperBound, false);
162+
resources.writeUpperBound(resetUpperBound);
163163
}
164164

165165
private TransportVersionId maybeGetExistingId(

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/GenerateInitialTransportVersionTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public void run() throws IOException {
5454
var definition = new TransportVersionDefinition(initialDefinitionName, List.of(id), false);
5555
resources.writeDefinition(definition);
5656
var newUpperBound = new TransportVersionUpperBound(upperBoundName, initialDefinitionName, id);
57-
resources.writeUpperBound(newUpperBound, false);
57+
resources.writeUpperBound(newUpperBound);
5858

5959
if (releaseVersion.getRevision() == 0) {
6060
Version currentVersion = getCurrentVersion().get();
6161
String currentUpperBoundName = getUpperBoundName(currentVersion);
6262
var currentUpperBound = new TransportVersionUpperBound(currentUpperBoundName, initialDefinitionName, id);
63-
resources.writeUpperBound(currentUpperBound, false);
63+
resources.writeUpperBound(currentUpperBound);
6464
}
6565
}
6666
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/GenerateTransportVersionDefinitionTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void resetUpperBound(
170170
resetValue = idsForUpperBound.get(idsForUpperBound.size() - 2);
171171
}
172172
var resetUpperBound = new TransportVersionUpperBound(upperBound.name(), resetValue.definition().name(), resetValue.id());
173-
resources.writeUpperBound(resetUpperBound, false);
173+
resources.writeUpperBound(resetUpperBound);
174174
}
175175

176176
private void removeUnusedNamedDefinitions(
@@ -190,6 +190,6 @@ private void removeUnusedNamedDefinitions(
190190
@Override
191191
protected void writeUpperBound(TransportVersionResourcesService resources, TransportVersionUpperBound newUpperBound)
192192
throws IOException {
193-
resources.writeUpperBound(newUpperBound, false);
193+
resources.writeUpperBound(newUpperBound);
194194
}
195195
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/ResolveTransportVersionConflictTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ protected Set<String> getTargetUpperBoundNames(
6969
@Override
7070
protected void writeUpperBound(TransportVersionResourcesService resources, TransportVersionUpperBound newUpperBound)
7171
throws IOException {
72-
resources.writeUpperBound(newUpperBound, true);
72+
resources.writeUpperBound(newUpperBound);
7373
}
7474
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ void writeDefinition(TransportVersionDefinition definition) throws IOException {
164164
definition.ids().stream().map(Object::toString).collect(Collectors.joining(",")) + "\n",
165165
StandardCharsets.UTF_8
166166
);
167+
gitCommand("add", path.toString());
167168
}
168169

169170
void deleteReferableDefinition(String name) throws IOException {
170171
Path path = transportResourcesDir.resolve(getDefinitionRelativePath(name, true));
171-
Files.deleteIfExists(path);
172+
if (Files.deleteIfExists(path)) {
173+
gitCommand("rm", "--ignore-unmatch", path.toString());
174+
}
172175
}
173176

174177
/** Return all unreferable definitions, mapped by their name. */
@@ -241,14 +244,12 @@ Set<String> getChangedUpperBoundNames() {
241244
}
242245

243246
/** Write the given upper bound to a file in the transport resources */
244-
void writeUpperBound(TransportVersionUpperBound upperBound, boolean stageInGit) throws IOException {
247+
void writeUpperBound(TransportVersionUpperBound upperBound) throws IOException {
245248
Path path = transportResourcesDir.resolve(getUpperBoundRelativePath(upperBound.name()));
246249
logger.debug("Writing upper bound [" + upperBound + "] to [" + path + "]");
247250
Files.writeString(path, upperBound.definitionName() + "," + upperBound.definitionId().complete() + "\n", StandardCharsets.UTF_8);
248251

249-
if (stageInGit) {
250-
gitCommand("add", path.toString());
251-
}
252+
gitCommand("add", path.toString());
252253
}
253254

254255
/** Return the path within the repository of the given latest */

0 commit comments

Comments
 (0)