Skip to content

Commit ae7b1b9

Browse files
committed
git timetravel -- add some more info about each commit
1 parent b3ff38d commit ae7b1b9

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/packages/frontend/frame-editors/time-travel-editor/actions.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
7777
syncdoc?: SyncDoc;
7878
private first_load: boolean = true;
7979
ambient_actions?: CodeEditorActions;
80-
private gitLog: { [t: number]: { hash: string; name: string } } = {};
80+
private gitLog: {
81+
[t: number]: { hash: string; name: string; subject: string };
82+
} = {};
8183

8284
_init2(): void {
8385
const { head, tail } = path_split(this.path);
@@ -450,7 +452,7 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
450452
try {
451453
const { stdout } = await this.gitCommand([
452454
"log",
453-
`--format="%at %H %an <%ae>"`,
455+
`--format="%at %H %an <%ae> %s"`,
454456
"--",
455457
]);
456458
this.gitLog = {};
@@ -463,12 +465,14 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
463465
const j = y.indexOf(" ", i + 1);
464466
if (j == -1) continue;
465467
const hash = y.slice(i + 1, j).trim();
466-
const name = y.slice(j + 1).trim();
468+
const k = y.indexOf("> ", j + 1);
469+
const name = y.slice(j + 1, k + 1).trim();
470+
const subject = y.slice(k + 1).trim();
467471
if (!x || !t0 || !hash) {
468472
continue;
469473
}
470474
const t = parseInt(t0) * 1000;
471-
this.gitLog[t] = { hash, name };
475+
this.gitLog[t] = { hash, name, subject };
472476
versions.push(new Date(t));
473477
}
474478
versions.reverse();
@@ -514,16 +518,33 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
514518
if (v0 == null || v1 == null) {
515519
return [];
516520
}
521+
if (v0 == v1) {
522+
const d = this.gitLog[`${v0}`];
523+
if (d) {
524+
return [d.name];
525+
} else {
526+
return [];
527+
}
528+
}
517529
const names: string[] = [];
518530
for (const t in this.gitLog) {
519531
const t0 = parseInt(t);
520-
if (t0 >= v0 && t0 <= v1) {
532+
if (v0 < t0 && t0 <= v1) {
521533
names.push(this.gitLog[t].name);
522534
}
523535
}
524536
return names;
525537
};
526538

539+
gitSubject = (version: number): string | undefined => {
540+
const versions = this.store.get("git_versions");
541+
if (versions == null) {
542+
return;
543+
}
544+
const t = versions.get(version)?.valueOf();
545+
return this.gitLog[`${t}`]?.subject;
546+
};
547+
527548
gitDoc = async (version: Date): Promise<ViewDocument | undefined> => {
528549
const str = await this.gitShow(version);
529550
if (str == null) {

src/packages/frontend/frame-editors/time-travel-editor/authors.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "@cocalc/util/compute/manager";
1414
import ComputeServer from "@cocalc/frontend/compute/inline";
1515
import { useTypedRedux } from "@cocalc/frontend/app-framework";
16+
import { plural } from "@cocalc/util/misc";
1617

1718
interface Props {
1819
actions: TimeTravelActions;
@@ -42,10 +43,15 @@ export function GitAuthors({ actions, version0, version1 }: Props) {
4243
for (const person of w) {
4344
v.push(
4445
<Popover
45-
title={<>{data[person].count} Commits</>}
46+
key={person}
47+
title={
48+
<>
49+
{data[person].count} {plural(data[person].count, "Commit")}
50+
</>
51+
}
4652
content={Array.from(data[person].emails).join(", ")}
4753
>
48-
{person} ({data[person].count})
54+
{person} {data[person].count > 1 ? `(${data[person].count})` : ""}
4955
</Popover>,
5056
);
5157
}

src/packages/frontend/frame-editors/time-travel-editor/time-travel.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,30 @@ export function TimeTravel(props: Props) {
366366
return <Loading theme={"medium"} />;
367367
};
368368

369+
const renderGitSubject = () => {
370+
const subject = props.actions.gitSubject(version);
371+
if (!subject) return;
372+
return (
373+
<div
374+
style={{
375+
padding: "5px 0 5px 15px",
376+
borderTop: "1px solid #ddd",
377+
background: "#fafafa",
378+
}}
379+
>
380+
{subject}
381+
</div>
382+
);
383+
};
384+
369385
if (loading) {
370386
return renderLoading();
371387
}
372388
return (
373389
<div className="smc-vfill">
374390
{renderControls()}
375391
{renderTimeSelect()}
392+
{gitMode && !changesMode && renderGitSubject()}
376393
<>
377394
{doc != null && docpath != null && docext != null && !changesMode && (
378395
<Viewer

0 commit comments

Comments
 (0)