Skip to content
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

fix file-history to be compared against parents, not previous snap #8008

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
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
42 changes: 27 additions & 15 deletions scopes/component/component-log/component-log.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { compact } from 'lodash';
import pMapSeries from 'p-map-series';
import { Version } from '@teambit/legacy/dist/scope/models';
import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils/path';
import { Ref } from '@teambit/legacy/dist/scope/objects';
import { getFilesDiff } from '@teambit/legacy/dist/consumer/component-ops/components-diff';
import chalk from 'chalk';
import getRemoteByName from '@teambit/legacy/dist/remotes/get-remote-by-name';
Expand All @@ -24,6 +25,7 @@ export type FileLog = {
date: string;
message: string;
fileHash: string;
parentFileHash?: string;
fileDiff?: string;
};

Expand Down Expand Up @@ -128,6 +130,27 @@ export class ComponentLogMain {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fileInComp = versionObj!.files.find((f) => f.relativePath === filePathRelativeInComponent);
if (!fileInComp) return;
const fileHash = fileInComp.file.toString();
const getFileHashFromParent = async (parent: Ref) => {
const parentObj = parent
? await workspace.scope.getBitObjectVersion(modelComp, parent.toString(), true)
: undefined;

const parentFileInComp = parentObj
? parentObj.files.find((f) => f.relativePath === filePathRelativeInComponent)
: undefined;

return parentFileInComp?.file.toString();
};
const fileHashesFromParent = versionObj ? await Promise.all(versionObj.parents.map(getFileHashFromParent)) : [];

const getParentFileHash = () => {
if (fileHashesFromParent.length === 0) return undefined;
if (fileHashesFromParent.length === 1) return fileHashesFromParent[0];
// if one parent has it, it means that this merge-snap didn't change the file.
if (fileHashesFromParent.includes(fileHash)) return fileHash;
return fileHashesFromParent[0];
};

results.push({
hash: logItem.hash,
Expand All @@ -136,26 +159,15 @@ export class ComponentLogMain {
email: logItem.email,
date: logItem.date || '<N/A>',
message: logItem.message,
fileHash: fileInComp.file.toString(),
fileHash,
parentFileHash: getParentFileHash(),
});
},
{ concurrency: 100 }
);

// remove entries that their fileHash is the same as the previous one
let lastFileHash: string;
results.forEach((item, index) => {
if (index === 0) {
lastFileHash = item.fileHash;
return;
}
if (item.fileHash === lastFileHash) {
delete results[index];
}
lastFileHash = item.fileHash;
});

return compact(results);
// remove entries that their fileHash is the same as their parent.
return results.filter((r) => r.fileHash !== r.parentFileHash);
}

async getFileLog(filePath: string) {
Expand Down