git-commit-id-maven-plugin icon indicating copy to clipboard operation
git-commit-id-maven-plugin copied to clipboard

Chinene commit message support better

Open timbersea opened this issue 2 years ago • 2 comments

the Chinese commit message in the git.properties will be transform as unicode such as \u4F18\u5316 ,it's diffcult to read for human

timbersea avatar Jun 16 '22 02:06 timbersea

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7 git.commit.message.short=\u611F\u53F9\u53F7 😓

timbersea avatar Jun 16 '22 09:06 timbersea

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7 git.commit.message.short=\u611F\u53F9\u53F7 😓

you can use <format>json</format> to resolve this

DogerRain avatar Jul 21 '22 06:07 DogerRain

it's so confused support Chinese git commit message,which properties determined the encodeing ? <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> my maven project config as below , but the Chinese git commit message like this git.commit.message.full=\u611F\u53F9\u53F7 git.commit.message.short=\u611F\u53F9\u53F7 😓

you can use <format>json</format> to resolve this

I don't think this solve the problem.

gary258796 avatar Oct 07 '22 02:10 gary258796

Below is method dumpProperties inside class PropertyManager from git-commit-id/git-commit-id-plugin-core, which is used by PropertiesFileGenerator's method maybeGeneratePropertiesFile, which is eventually called inside class GitCommitIdMojo.

public static void dumpProperties(OutputStream outputStream, OrderedProperties sortedLocalProperties) throws IOException {
        Writer outputWriter = new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1);

        try {
            outputWriter.write("#Generated by Git-Commit-Id-Plugin");
            outputWriter.write(System.getProperty("line.separator"));
            Iterator var3 = sortedLocalProperties.entrySet().iterator();

            while(var3.hasNext()) {
                Map.Entry<String, String> e = (Map.Entry)var3.next();
                String key = saveConvert((String)e.getKey(), true, true);
                String val = saveConvert((String)e.getValue(), false, true);
                outputWriter.write(key + "=" + val);
                outputWriter.write(System.getProperty("line.separator"));
            }
        } catch (Throwable var8) {
            try {
                outputWriter.close();
            } catch (Throwable var7) {
                var8.addSuppressed(var7);
            }

            throw var8;
        }

        outputWriter.close();
    }

function saveConvert has it's third parameter as escapeUnicode, this is why now Chinese inside git.properties are transformed to unicode.

Maybe we have to modify git-commit-id/git-commit-id-plugin-core to accept a new parameter to control whether escapeUnicode or not ?

gary258796 avatar Oct 07 '22 05:10 gary258796

Will do a pull request after git-commit-id/git-commit-id-plugin-core have 6.0.0 version out.

We can then control escape unicode or not by last parameter, which is a boolean, of method maybeGeneratePropertiesFile . public void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, File base, String propertiesFilename, Charset sourceCharset, boolean escapeUnicode) throws GitCommitIdExecutionException

Pull request to github.com/git-commit-id/git-commit-id-plugin-core in order to control whether escapeUnicode or not by a new parameter.

gary258796 avatar Oct 08 '22 02:10 gary258796