Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions src/commands/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function getSwitchCommandsDisposable() {
}),
commands.registerCommand(SWITCH_REPO_COMMAND, async () => {
const quickPick = window.createQuickPick();
quickPick.canSelectMany = true; // 启用多选

const items =
gitService
Expand All @@ -61,20 +62,26 @@ export function getSwitchCommandsDisposable() {
quickPick.title = "Switch Repository";
quickPick.placeholder = "Search repo by path";
quickPick.items = items;
quickPick.activeItems = items.filter(
({ label }) => label === state.logOptions.repo

// 设置 activeItems 和 selectedItems,确保之前选中的仓库显示为选中状态
const selectedRepos = state.logOptions.repo || [];
quickPick.activeItems = items.filter(({ label }) =>
selectedRepos.includes(label)
);
quickPick.selectedItems = items.filter(({ label }) =>
selectedRepos.includes(label)
);

quickPick.onDidChangeSelection((selection) => {
const [item] = selection;
const { label: repo } = item;
quickPick.onDidAccept(() => {
const selection = quickPick.selectedItems; // 获取选中的项目
const repo = selection.map((item) => item.label); // 提取所有选中的仓库路径
const switchSubscriber = source.getSwitchSubscriber();
if (!switchSubscriber) {
return;
}

state.logOptions = { repo };
source.getCommits(switchSubscriber, state.logOptions);
state.logOptions = { repo }; // 将选中的仓库存储为数组
source.getCommits(switchSubscriber, state.logOptions); // 传递选中的仓库
quickPick.dispose();
});

Expand Down Expand Up @@ -109,9 +116,9 @@ export function getSwitchCommandsDisposable() {
...localBranchRefs,
...remoteBranchRefs,
...otherRefs,
].map(({ type, name, hash }) => ({
].map(({ type, name, hash, repos }) => ({
label: `$(${REF_TYPE_DETAIL_MAP[type]?.icon}) ${name}`,
description: `${
description: `${repos} ${
REF_TYPE_DETAIL_MAP[type]?.descriptionPrefix
}${hash.substring(0, 8)}`,
ref: name,
Expand Down
5 changes: 5 additions & 0 deletions src/git/changes/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Change {
readonly originalUri: Uri;
readonly renameUri: Uri | undefined;
readonly status: Status;
readonly repository: string;
}

export function parseGitChanges(repoPath: string, gitResult: string) {
Expand All @@ -26,6 +27,8 @@ export function parseGitChanges(repoPath: string, gitResult: string) {
entriesLoop: while (index < entries.length - 1) {
const change = entries[index++];
const resourcePath = entries[index++];
const repositoryName = repoPath.split("\\").slice(-1)[0];

if (!change || !resourcePath) {
break;
}
Expand Down Expand Up @@ -72,6 +75,7 @@ export function parseGitChanges(repoPath: string, gitResult: string) {
renameUri: uri,
originalUri,
status: Status.INDEX_RENAMED,
repository: repositoryName,
});

continue;
Expand All @@ -86,6 +90,7 @@ export function parseGitChanges(repoPath: string, gitResult: string) {
originalUri,
uri: originalUri,
renameUri: originalUri,
repository: repositoryName,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/git/changes/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function getPathMap(changesCollection: ChangesCollection) {
uri: originalUri,
originalUri,
renameUri: originalUri,
repository: repoPath,
};
if (pathMap[originalPath]) {
pathMap[originalPath].changeStack.push({
Expand Down
21 changes: 17 additions & 4 deletions src/git/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type ICommit = [
string,
/** author date */
string,
/** repository name */
string,
ICommitGraphSlice?
];

Expand All @@ -26,7 +28,11 @@ export type IRoughCommit = [
/** parents */
string[],
/** commit data */
string
string,
/** repository name */
string,
/** author date */
number
];

export enum CommitIndex {
Expand All @@ -38,12 +44,13 @@ export enum CommitIndex {
AUTHOR_EMAIL,
AUTHOR_NAME,
AUTHOR_DATE,
REPOSITORY_NAME,
GRAPH_SLICE,
}

export const REFS_SEPARATOR = ", ";

export function parseCommits(data: string) {
export function parseCommits(data: string, repo: string) {
const commitRegex =
/([0-9a-f]{40})\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)(?:\n([^]*?))?(?:\x00)/gm;

Expand All @@ -52,6 +59,7 @@ export function parseCommits(data: string) {
let commitData;
let ref;
let parents;
let authorDate
let match;

do {
Expand All @@ -60,13 +68,15 @@ export function parseCommits(data: string) {
break;
}

[commitData, ref, , , , , , parents] = match;
[commitData, ref, , , , authorDate, , parents] = match;

// Stop excessive memory usage by using substr -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
const commit: IRoughCommit = [
` ${ref}`.substr(1),
parents ? parents.split(" ") : [],
commitData,
repo,
authorDate ? Number(authorDate) * 1000 : 0
];

commits.push(commit);
Expand All @@ -77,7 +87,7 @@ export function parseCommits(data: string) {

export function parseCommit(commitData: string): ICommit {
const commitRegex =
/([0-9a-f]{40})\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)(?:\n([^]*?))?(?:\x00)(.*)\n(.*)\n(.*)/g;
/([0-9a-f]{40})\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)(?:\n([^]*?))?(?:\x00)(.*)\n(.*)\n(.*)\n(.*)/g;

let ref;
let refNames;
Expand All @@ -87,6 +97,7 @@ export function parseCommit(commitData: string): ICommit {
let commitDate;
let parents;
let message;
let repositoryName;
let commitPosition;
let commitColor;
let stringifiedLines;
Expand All @@ -104,6 +115,7 @@ export function parseCommit(commitData: string): ICommit {
commitDate,
parents,
message,
repositoryName,
commitPosition,
commitColor,
stringifiedLines,
Expand All @@ -123,6 +135,7 @@ export function parseCommit(commitData: string): ICommit {
` ${authorEmail}`.substr(1),
` ${authorName}`.substr(1),
new Date(Number(commitDate) * 1000).toLocaleString(),
repositoryName,
[Number(commitPosition), commitColor, JSON.parse(stringifiedLines)],
];
}
4 changes: 2 additions & 2 deletions src/git/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class GitGraph {

private setGraphToCommits(commits: IRoughCommit[], setGraph = true) {
return commits.map(
([hash, parents, commitData]) =>
`${commitData}${
([hash, parents, commitData, repositoryName]) =>
`${commitData}${repositoryName}\n${
setGraph
? this.getGraphSlice(hash, parents)
: this.getSingleLineGraphSlice(hash, parents)
Expand Down
Loading