Skip to content

use local timezone for commit (add --use-localtime option) #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
use localtime
  • Loading branch information
m-tmatma committed Jan 3, 2023
commit 3a94c2672cc0ded2cce5d265752b1125915bd7c0
15 changes: 13 additions & 2 deletions src/repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QDir>
#include <QFile>
#include <QLinkedList>
#include <time.h>

static const int maxSimultaneousProcesses = 100;

Expand Down Expand Up @@ -1077,10 +1078,15 @@ bool FastImportRepository::Transaction::commitNote(const QByteArray &noteText, b
message = "Appending Git note for current " + commitRef + "\n";
}

struct tm lt = {0};
localtime_r((const time_t*)&datetime, &lt);
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");
Expand Down Expand Up @@ -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, &lt);
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);
Expand Down