From 3a94c2672cc0ded2cce5d265752b1125915bd7c0 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Tue, 3 Jan 2023 19:58:59 +0900 Subject: [PATCH 1/2] use localtime --- src/repository.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/repository.cpp b/src/repository.cpp index b926ad4..2d809e0 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -24,6 +24,7 @@ #include #include #include +#include static const int maxSimultaneousProcesses = 100; @@ -1077,10 +1078,15 @@ bool FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, b message = "Appending Git note for current " + commitRef + "\n"; } + struct tm lt = {0}; + localtime_r((const time_t*)&datetime, <); + QString timezone; + timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + QByteArray s(""); s.append("commit refs/notes/commits\n"); s.append("mark :" + QByteArray::number(maxMark) + "\n"); - s.append("committer " + author + " " + QString::number(datetime) + " +0000" + "\n"); + s.append("committer " + author + " " + QString::number(datetime) + " " + timezone + "\n"); s.append("data " + QString::number(message.length()) + "\n"); s.append(message + "\n"); s.append("N inline " + commitRef + "\n"); @@ -1148,10 +1154,15 @@ int FastImportRepository::Transaction::commit() if (!branchRef.startsWith("refs/")) branchRef.prepend("refs/heads/"); + struct tm lt = {0}; + localtime_r((const time_t*)&datetime, <); + QString timezone; + timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + QByteArray s(""); s.append("commit " + branchRef + "\n"); s.append("mark :" + QByteArray::number(mark) + "\n"); - s.append("committer " + author + " " + QString::number(datetime).toUtf8() + " +0000" + "\n"); + s.append("committer " + author + " " + QString::number(datetime).toUtf8() + " " + timezone + "\n"); s.append("data " + QString::number(message.length()) + "\n"); s.append(message + "\n"); repository->fastImport.write(s); From 61b9d30107863d038a4e57f22c7da35ee8256195 Mon Sep 17 00:00:00 2001 From: Masaru Tsuchiyama Date: Tue, 3 Jan 2023 21:50:52 +0900 Subject: [PATCH 2/2] add --use-localtime option --- src/main.cpp | 1 + src/repository.cpp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dd1d452..c674f0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,6 +150,7 @@ static const CommandLineOption options[] = { {"--svn-ignore", "Import svn-ignore-properties via .gitignore"}, {"--propcheck", "Check for svn-properties except svn-ignore"}, {"--fast-import-timeout SECONDS", "number of seconds to wait before terminating fast-import, 0 to wait forever"}, + {"--use-localtime", "use local time for commit"}, {"-h, --help", "show help"}, {"-v, --version", "show version"}, CommandLineLastOption diff --git a/src/repository.cpp b/src/repository.cpp index 2d809e0..cb42e86 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -1078,10 +1078,14 @@ bool FastImportRepository::Transaction::commitNote(const QByteArray ¬eText, b message = "Appending Git note for current " + commitRef + "\n"; } - struct tm lt = {0}; - localtime_r((const time_t*)&datetime, <); QString timezone; - timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + if(CommandLineParser::instance()->contains("use-localtime")) { + struct tm lt = {0}; + localtime_r((const time_t*)&datetime, <); + timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + } else { + timezone = "+0000"; + } QByteArray s(""); s.append("commit refs/notes/commits\n"); @@ -1154,10 +1158,14 @@ int FastImportRepository::Transaction::commit() if (!branchRef.startsWith("refs/")) branchRef.prepend("refs/heads/"); - struct tm lt = {0}; - localtime_r((const time_t*)&datetime, <); QString timezone; - timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + if(CommandLineParser::instance()->contains("use-localtime")) { + struct tm lt = {0}; + localtime_r((const time_t*)&datetime, <); + timezone.sprintf( "%+02d%02d", lt.tm_gmtoff / 3600, (lt.tm_gmtoff / 60) % 60 ); + } else { + timezone = "+0000"; + } QByteArray s(""); s.append("commit " + branchRef + "\n");