Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmele committed May 1, 2022
1 parent f9fdb46 commit 3c1b0e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion dep/libgit2/libgit2
72 changes: 39 additions & 33 deletions src/git/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,44 @@ struct FilterInfo {

QString quote(const QString &path) { return QString("\"%1\"").arg(path); }

int apply(git_filter *self, void **payload, git_buf *to, const git_buf *from,
const git_filter_source *src) {
FilterInfo *info = reinterpret_cast<FilterInfo *>(self);
git_filter_mode_t mode = git_filter_source_mode(src);
QString command = (mode == GIT_FILTER_SMUDGE) ? info->smudge : info->clean;

// Substitute path.
command.replace("%f", quote(git_filter_source_path(src)));

QString bash = Command::bashPath();
if (bash.isEmpty())
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

QProcess process;
git_repository *repo = git_filter_source_repo(src);
process.setWorkingDirectory(git_repository_workdir(repo));

process.start(bash, {"-c", command});
if (!process.waitForStarted())
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

process.write(from->ptr, from->size);
process.closeWriteChannel();

if (!process.waitForFinished() || process.exitCode()) {
git_error_set_str(GIT_ERROR_FILTER, process.readAllStandardError());
return info->required ? GIT_EUSER : GIT_PASSTHROUGH;
}

QByteArray data = process.readAll();
git_buf_set(to, data.constData(), data.length());
return 0;
int stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
return -1;
// FilterInfo *info = reinterpret_cast<FilterInfo *>(self);
// git_filter_mode_t mode = git_filter_source_mode(src);
// QString command = (mode == GIT_FILTER_SMUDGE) ? info->smudge : info->clean;

// // Substitute path.
// command.replace("%f", quote(git_filter_source_path(src)));

// QString bash = Command::bashPath();
// if (bash.isEmpty())
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

// QProcess process;
// git_repository *repo = git_filter_source_repo(src);
// process.setWorkingDirectory(git_repository_workdir(repo));

// process.start(bash, {"-c", command});
// if (!process.waitForStarted())
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;

// process.write(from->ptr, from->size);
// process.closeWriteChannel();

// if (!process.waitForFinished() || process.exitCode()) {
// git_error_set_str(GIT_ERROR_FILTER, process.readAllStandardError());
// return info->required ? GIT_EUSER : GIT_PASSTHROUGH;
// }

// QByteArray data = process.readAll();
// git_buf_set(to, data.constData(), data.length());
// return 0;
}

} // namespace
Expand Down Expand Up @@ -101,7 +107,7 @@ void Filter::init() {
info.name = key.toUtf8();
info.attributes = kFilterFmt.arg(key).toUtf8();

info.filter.apply = &apply;
info.filter.stream = &stream;
info.filter.attributes = info.attributes.constData();
git_filter_register(info.name.constData(), &info.filter,
GIT_FILTER_DRIVER_PRIORITY);
Expand Down

0 comments on commit 3c1b0e2

Please sign in to comment.