From 82939782eb0eddb03afe7f667e9c75f95c04e950 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Tue, 11 Jul 2023 15:12:08 +0200 Subject: [PATCH 1/4] bump svelte-loadable-store --- package.json | 2 +- pnpm-lock.yaml | 20 +++++++++---------- src/lib/stores/bookmarks.ts | 4 ++-- src/lib/stores/deltas.ts | 4 ++-- src/lib/stores/files.ts | 4 ++-- src/lib/stores/sessions.ts | 4 ++-- src/lib/vbranches/branchStoresCache.ts | 5 +++-- .../projects/[projectId]/FileSummaries.svelte | 4 ++-- .../[projectId]/player/+layout.svelte | 4 ++-- .../[projectId]/player/[date]/+layout.svelte | 8 ++++---- .../player/[date]/SessionCard.svelte | 4 ++-- .../player/[date]/SessionNavigations.svelte | 16 ++++----------- .../player/[date]/SessionsList.svelte | 6 +++--- .../player/[date]/[sessionId]/+page.svelte | 10 +++++----- .../player/[date]/[sessionId]/Frame.svelte | 6 +++--- .../player/[date]/[sessionId]/Info.svelte | 6 +++--- .../player/[date]/[sessionId]/Playback.svelte | 4 ++-- .../player/[date]/[sessionId]/Slider.svelte | 4 ++-- src/routes/repo/[projectId]/+page.svelte | 8 ++++---- 19 files changed, 58 insertions(+), 65 deletions(-) diff --git a/package.json b/package.json index 247e50dc4..afc2a7cee 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "svelte-check": "^3.0.1", "svelte-floating-ui": "^1.5.2", "svelte-french-toast": "^1.0.3", - "svelte-loadable-store": "^1.2.3", + "svelte-loadable-store": "^2.0.0", "svelte-outclick": "^3.5.0", "svelte-resize-observer": "^2.0.0", "tailwindcss": "^3.1.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6dfb7d006..7b41e3dcb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -200,8 +200,8 @@ devDependencies: specifier: ^1.0.3 version: 1.0.3(svelte@3.55.1) svelte-loadable-store: - specifier: ^1.2.3 - version: 1.2.3(svelte@3.55.1) + specifier: ^2.0.0 + version: 2.0.0(svelte@3.55.1) svelte-outclick: specifier: ^3.5.0 version: 3.5.0(svelte@3.55.1) @@ -213,10 +213,10 @@ devDependencies: version: 3.2.4(postcss@8.4.21) tauri-plugin-log-api: specifier: github:tauri-apps/tauri-plugin-log - version: github.com/tauri-apps/tauri-plugin-log/21921031d74f871180381317a338559f588ad8e9 + version: github.com/tauri-apps/tauri-plugin-log/fbbb126e6d7fba7a7e6772d33f99c0fb689f32b6 tauri-plugin-websocket-api: specifier: github:tauri-apps/tauri-plugin-websocket - version: github.com/tauri-apps/tauri-plugin-websocket/7832cb121d2ecaf6b52c9bdee77df18fddaac5d9 + version: github.com/tauri-apps/tauri-plugin-websocket/39b7ba2c0c27a9b0093b00120830ed23774f5403 tinykeys: specifier: ^1.4.0 version: 1.4.0 @@ -4717,8 +4717,8 @@ packages: svelte: 3.55.1 dev: true - /svelte-loadable-store@1.2.3(svelte@3.55.1): - resolution: {integrity: sha512-efoCRCGLxzU+RE1D09cpnKKBO2CVXAzjUY0/RatOtPXSNPbb0/HeGcV/baH5davabwiDm7iWf2rqI9ogIRQ1Pw==} + /svelte-loadable-store@2.0.0(svelte@3.55.1): + resolution: {integrity: sha512-2mnbj99fnbQg4WwXW3WZWUqAbcaXkHacFFulb7r+VdSic9PkkKq/117V94lVeCrC9BxMR7KaOdESE7+JZTsWxg==} peerDependencies: svelte: ^3.0.0 dependencies: @@ -5459,16 +5459,16 @@ packages: engines: {node: '>=12.20'} dev: true - github.com/tauri-apps/tauri-plugin-log/21921031d74f871180381317a338559f588ad8e9: - resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/21921031d74f871180381317a338559f588ad8e9} + github.com/tauri-apps/tauri-plugin-log/fbbb126e6d7fba7a7e6772d33f99c0fb689f32b6: + resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/fbbb126e6d7fba7a7e6772d33f99c0fb689f32b6} name: tauri-plugin-log-api version: 0.0.0 dependencies: '@tauri-apps/api': 1.4.0 dev: true - github.com/tauri-apps/tauri-plugin-websocket/7832cb121d2ecaf6b52c9bdee77df18fddaac5d9: - resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/7832cb121d2ecaf6b52c9bdee77df18fddaac5d9} + github.com/tauri-apps/tauri-plugin-websocket/39b7ba2c0c27a9b0093b00120830ed23774f5403: + resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/39b7ba2c0c27a9b0093b00120830ed23774f5403} name: tauri-plugin-websocket-api version: 0.0.0 dependencies: diff --git a/src/lib/stores/bookmarks.ts b/src/lib/stores/bookmarks.ts index 26a9b953e..29bace36e 100644 --- a/src/lib/stores/bookmarks.ts +++ b/src/lib/stores/bookmarks.ts @@ -1,4 +1,4 @@ -import { writable, type Loadable, derived, Value } from 'svelte-loadable-store'; +import { writable, type Loadable, derived, Loaded } from 'svelte-loadable-store'; import { bookmarks, type Bookmark } from '$lib/api'; import { get as getValue, type Readable } from '@square/svelte-store'; @@ -12,7 +12,7 @@ export function list(params: { projectId: string }) { const oldValue = getValue(store); if (oldValue.isLoading) { bookmarks.list(params).then(set); - } else if (Value.isError(oldValue.value)) { + } else if (Loaded.isError(oldValue)) { bookmarks.list(params).then(set); } else { set(oldValue.value.filter((b) => b.timestampMs !== bookmark.timestampMs).concat(bookmark)); diff --git a/src/lib/stores/deltas.ts b/src/lib/stores/deltas.ts index 1fa4f5411..d222ac7b2 100644 --- a/src/lib/stores/deltas.ts +++ b/src/lib/stores/deltas.ts @@ -1,4 +1,4 @@ -import { writable, type Loadable, Value } from 'svelte-loadable-store'; +import { writable, type Loadable, Loaded } from 'svelte-loadable-store'; import { deltas, type Delta } from '$lib/api'; import { get, type Readable } from '@square/svelte-store'; @@ -13,7 +13,7 @@ export default (params: { projectId: string; sessionId: string }) => { const oldValue = get(store); if (oldValue.isLoading) { deltas.list(params).then(set); - } else if (Value.isError(oldValue.value)) { + } else if (Loaded.isError(oldValue)) { deltas.list(params).then(set); } else { set({ diff --git a/src/lib/stores/files.ts b/src/lib/stores/files.ts index ac72a105c..405693987 100644 --- a/src/lib/stores/files.ts +++ b/src/lib/stores/files.ts @@ -1,4 +1,4 @@ -import { writable, type Loadable, Value } from 'svelte-loadable-store'; +import { writable, type Loadable, Loaded } from 'svelte-loadable-store'; import { files } from '$lib/api'; import { get, type Readable } from '@square/svelte-store'; @@ -13,7 +13,7 @@ export default (params: { projectId: string; sessionId: string }) => { const oldValue = get(store); if (oldValue.isLoading) { files.list(params).then(set); - } else if (Value.isError(oldValue.value)) { + } else if (Loaded.isError(oldValue)) { files.list(params).then(set); } else { set({ diff --git a/src/lib/stores/sessions.ts b/src/lib/stores/sessions.ts index 490ed3cf3..1b4f6665d 100644 --- a/src/lib/stores/sessions.ts +++ b/src/lib/stores/sessions.ts @@ -1,4 +1,4 @@ -import { derived, writable, type Loadable, Value } from 'svelte-loadable-store'; +import { derived, writable, type Loadable, Loaded } from 'svelte-loadable-store'; import { sessions, type Session } from '$lib/api'; import { get, type Readable } from '@square/svelte-store'; @@ -13,7 +13,7 @@ export default (params: { projectId: string }) => { const oldValue = get(store); if (oldValue.isLoading) { sessions.list(params).then(set); - } else if (Value.isError(oldValue.value)) { + } else if (Loaded.isError(oldValue)) { sessions.list(params).then(set); } else { set( diff --git a/src/lib/vbranches/branchStoresCache.ts b/src/lib/vbranches/branchStoresCache.ts index c93355f3e..3c6c03e3b 100644 --- a/src/lib/vbranches/branchStoresCache.ts +++ b/src/lib/vbranches/branchStoresCache.ts @@ -1,4 +1,4 @@ -import { writable, type Loadable, Value } from 'svelte-loadable-store'; +import { writable, type Loadable, Loaded } from 'svelte-loadable-store'; import type { Readable } from '@square/svelte-store'; import { git } from '$lib/api/ipc'; import { stores } from '$lib'; @@ -19,10 +19,11 @@ export class BranchStoresCache { if (cachedStore) { return cachedStore; } + const writableStore = writable(ipc.listVirtualBranches({ projectId }), (set) => { stores.sessions({ projectId }).subscribe((sessions) => { if (sessions.isLoading) return; - if (Value.isError(sessions.value)) return; + if (Loaded.isError(sessions)) return; const lastSession = sessions.value.at(-1); if (!lastSession) return; return stores.deltas({ projectId, sessionId: lastSession.id }).subscribe(() => { diff --git a/src/routes/projects/[projectId]/FileSummaries.svelte b/src/routes/projects/[projectId]/FileSummaries.svelte index b37dd7f20..cc12fad43 100644 --- a/src/routes/projects/[projectId]/FileSummaries.svelte +++ b/src/routes/projects/[projectId]/FileSummaries.svelte @@ -2,7 +2,7 @@ import { format, startOfDay } from 'date-fns'; import type { Delta } from '$lib/api'; import { generateBuckets } from './histogram'; - import { derived, Value } from 'svelte-loadable-store'; + import { derived, Loaded } from 'svelte-loadable-store'; import FileActivity from './FileActivity.svelte'; import { page } from '$app/stores'; import { Link } from '$lib/components'; @@ -44,7 +44,7 @@

Loading file changes...

- {:else if Value.isError($deltasByDate.value) || Value.isError($buckets.value)} + {:else if Loaded.isError($deltasByDate) || Loaded.isError($buckets)}
  • diff --git a/src/routes/projects/[projectId]/player/+layout.svelte b/src/routes/projects/[projectId]/player/+layout.svelte index 4c9042d25..c1a0e5379 100644 --- a/src/routes/projects/[projectId]/player/+layout.svelte +++ b/src/routes/projects/[projectId]/player/+layout.svelte @@ -2,7 +2,7 @@ import { page } from '$app/stores'; import { stores, api } from '$lib'; import { format } from 'date-fns'; - import { derived, Value } from 'svelte-loadable-store'; + import { derived, Loaded } from 'svelte-loadable-store'; const sessions = stores.sessions({ projectId: $page.params.projectId }); @@ -32,7 +32,7 @@
    - {#if !$dates.isLoading && Value.isValue($dates.value)} + {#if !$dates.isLoading && Loaded.isValue($dates)} {#if $dates.value.length === 0}

    I haven't seen any changes yet

    diff --git a/src/routes/projects/[projectId]/player/[date]/+layout.svelte b/src/routes/projects/[projectId]/player/[date]/+layout.svelte index 4aca5549e..b08b3a911 100644 --- a/src/routes/projects/[projectId]/player/[date]/+layout.svelte +++ b/src/routes/projects/[projectId]/player/[date]/+layout.svelte @@ -1,7 +1,7 @@ @@ -48,7 +48,7 @@ > {#each visibleSessions as session, i} {@const isCurrent = session.id === currentSession?.id} - {#if session.visible && !$visibleDeltas.isLoading && !Value.isError($visibleDeltas.value) && !$visibleFiles.isLoading && !Value.isError($visibleFiles.value)} + {#if session.visible && !$visibleDeltas.isLoading && !Loaded.isError($visibleDeltas) && !$visibleFiles.isLoading && !Loaded.isError($visibleFiles)} { if (sessions.isLoading) return; - if (Value.isError(sessions.value)) return; + if (Loaded.isError(sessions)) return; if (sessions.value.length === 0) return; if (!sessions.value.some((s) => s.id === $currentSessionId)) { $currentSessionId = sessions.value[0].id; @@ -74,7 +74,7 @@ $: { // this hook updates player value if current page url has changed - if (!$richSessions.isLoading && Value.isValue($richSessions.value)) { + if (!$richSessions.isLoading && Loaded.isValue($richSessions)) { const currentSessionIndex = $richSessions.value.findIndex( (s) => s.id === $page.params.sessionId ); @@ -83,7 +83,7 @@ .filter((_, index) => index < currentSessionIndex) .reduce((acc, s) => { const deltas = get(s.deltas); - if (!deltas.isLoading && Value.isValue(deltas.value)) { + if (!deltas.isLoading && Loaded.isValue(deltas)) { return acc + deltas.value.length; } else { return acc; @@ -100,7 +100,7 @@ />

    Loading...

    -{:else if Value.isError($richSessions.value)} +{:else if Loaded.isError($richSessions)}

    Something went wrong

    diff --git a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Frame.svelte b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Frame.svelte index 12d73ea31..3c7a2b24e 100644 --- a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Frame.svelte +++ b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Frame.svelte @@ -3,7 +3,7 @@ import type { Frame } from './frame'; import { DeltasViewer } from '$lib/components'; import type { Readable } from '@square/svelte-store'; - import { Value, type Loadable } from 'svelte-loadable-store'; + import { Loaded, type Loadable } from 'svelte-loadable-store'; export let context: number; export let fullContext: boolean; @@ -17,8 +17,8 @@ if ( !$deltas.isLoading && !$files.isLoading && - Value.isValue($deltas.value) && - Value.isValue($files.value) + Loaded.isValue($deltas) && + Loaded.isValue($files) ) { let i = value; for (const j in $deltas.value) { diff --git a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Info.svelte b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Info.svelte index 324a104e6..57f3b10f2 100644 --- a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Info.svelte +++ b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Info.svelte @@ -3,8 +3,8 @@ import { collapse } from '$lib/paths'; import { IconBookmark, IconBookmarkFilled } from '$lib/icons'; import { format } from 'date-fns'; - import { Value } from 'svelte-loadable-store'; import { page } from '$app/stores'; + import { Loaded } from 'svelte-loadable-store'; export let timestampMs: number; export let filename: string; @@ -13,7 +13,7 @@ const toggleBookmark = () => { if ($bookmark.isLoading) return; - if (Value.isError($bookmark.value)) return; + if (Loaded.isError($bookmark)) return; api.bookmarks.upsert( !$bookmark.value ? { @@ -30,7 +30,7 @@ }; -{#if !$bookmark.isLoading && !Value.isError($bookmark.value)} +{#if !$bookmark.isLoading && !Loaded.isError($bookmark)}
    import type { Bookmark, Delta } from '$lib/api'; - import { derived, Value, type Loadable } from 'svelte-loadable-store'; + import { derived, Loaded, type Loadable } from 'svelte-loadable-store'; import type { Readable } from '@square/svelte-store'; import { ModuleChapters, ModuleMarkers, type Marker } from './slider'; import { JSR, ModuleSlider } from 'mm-jsr'; @@ -89,7 +89,7 @@ }; -{#if !$totalDeltas.isLoading && Value.isValue($totalDeltas.value) && !$chapters.isLoading && Value.isValue($chapters.value) && !$markers.isLoading && Value.isValue($markers.value)} +{#if !$totalDeltas.isLoading && Loaded.isValue($totalDeltas) && !$chapters.isLoading && Loaded.isValue($chapters) && !$markers.isLoading && Loaded.isValue($markers)}
    Date: Tue, 11 Jul 2023 13:49:31 +0200 Subject: [PATCH 2/4] store target upstream name separately --- src-tauri/src/gb_repository/repository.rs | 11 +- src-tauri/src/virtual_branches/iterator.rs | 5 +- src-tauri/src/virtual_branches/mod.rs | 124 ++++++++++-------- src-tauri/src/virtual_branches/target/mod.rs | 52 ++++++-- .../src/virtual_branches/target/reader.rs | 59 ++++++++- .../src/virtual_branches/target/writer.rs | 77 +++++++---- .../handlers/project_file_change_tests.rs | 5 +- src/lib/vbranches/types.ts | 5 +- src/routes/repo/[projectId]/Tray.svelte | 2 +- 9 files changed, 238 insertions(+), 102 deletions(-) diff --git a/src-tauri/src/gb_repository/repository.rs b/src-tauri/src/gb_repository/repository.rs index 89e1f0f36..5e2846ea7 100644 --- a/src-tauri/src/gb_repository/repository.rs +++ b/src-tauri/src/gb_repository/repository.rs @@ -563,9 +563,9 @@ impl Repository { // lookup a branch by name let branch = repo.find_branch(target_branch, git2::BranchType::Remote)?; - let remote = repo.branch_remote_name(branch.get().name().unwrap())?; - let remote_url = repo.find_remote(remote.as_str().unwrap())?; - let remote_url_str = remote_url.url().unwrap(); + let remote_name = repo.branch_remote_name(branch.get().name().unwrap())?; + let remote = repo.find_remote(remote_name.as_str().unwrap())?; + let remote_url = remote.url().unwrap(); // get a list of currently active virtual branches @@ -604,8 +604,9 @@ impl Repository { } let target = virtual_branches::target::Target { - name: branch.name().unwrap().unwrap().to_string(), - remote: remote_url_str.to_string(), + branch_name: branch.name()?.unwrap().to_string(), + remote_name: remote.name().unwrap().to_string(), + remote_url: remote_url.to_string(), sha: commit_oid, behind: 0, }; diff --git a/src-tauri/src/virtual_branches/iterator.rs b/src-tauri/src/virtual_branches/iterator.rs index fd8f92e0c..847dbb66a 100644 --- a/src-tauri/src/virtual_branches/iterator.rs +++ b/src-tauri/src/virtual_branches/iterator.rs @@ -101,8 +101,9 @@ mod tests { fn test_target() -> target::Target { target::Target { - name: format!("target_name_{}", unsafe { TEST_TARGET_INDEX }), - remote: format!("remote_{}", unsafe { TEST_TARGET_INDEX }), + branch_name: format!("branch name{}", unsafe { TEST_TARGET_INDEX }), + remote_name: format!("remote name {}", unsafe { TEST_TARGET_INDEX }), + remote_url: format!("remote url {}", unsafe { TEST_TARGET_INDEX }), sha: git2::Oid::from_str(&format!( "0123456789abcdef0123456789abcdef0123456{}", unsafe { TEST_TARGET_INDEX } diff --git a/src-tauri/src/virtual_branches/mod.rs b/src-tauri/src/virtual_branches/mod.rs index 710e5ca2d..1aa5175b2 100644 --- a/src-tauri/src/virtual_branches/mod.rs +++ b/src-tauri/src/virtual_branches/mod.rs @@ -752,7 +752,6 @@ pub fn list_virtual_branches( let mut upstream_commit = None; if !branch.upstream.is_empty() { // get the target remote - let remote_url = &default_target.remote; let remotes = repo.remotes()?; let mut upstream_remote = None; for remote_name in remotes.iter() { @@ -767,7 +766,7 @@ pub fn list_virtual_branches( None => continue, }; - if url == remote_url { + if url == default_target.remote_url { upstream_remote = Some(remote); break; } @@ -1564,12 +1563,12 @@ pub fn update_branch_target( let repo = &project_repository.git_repository; let branch = repo - .find_branch(&target.name, git2::BranchType::Remote) - .context(format!("failed to find branch {}", target.name))?; - let new_target_commit = branch - .get() - .peel_to_commit() - .context(format!("failed to peel branch {} to commit", target.name))?; + .find_branch(&target.branch_name, git2::BranchType::Remote) + .context(format!("failed to find branch {}", target.branch_name))?; + let new_target_commit = branch.get().peel_to_commit().context(format!( + "failed to peel branch {} to commit", + target.branch_name + ))?; let new_target_oid = new_target_commit.id(); // // if the target has not changed, do nothing @@ -1938,13 +1937,13 @@ pub fn get_target_data( Some(mut target) => { let repo = &project_repository.git_repository; let branch = repo - .find_branch(&target.name, git2::BranchType::Remote) + .find_branch(&target.branch_name, git2::BranchType::Remote) .unwrap(); let commit = branch.get().peel_to_commit().unwrap(); let oid = commit.id(); target.behind = project_repository .behind(oid, target.sha) - .context(format!("failed to get behind for {}", target.name))?; + .context(format!("failed to get behind for {}", target.branch_name))?; Ok(Some(target)) } } @@ -2026,8 +2025,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + remote_name: "origin".to_string(), + branch_name: "master".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2093,8 +2093,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + remote_name: "origin".to_string(), + branch_name: "master".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2153,8 +2154,9 @@ mod tests { gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2200,8 +2202,9 @@ mod tests { gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2242,8 +2245,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2329,8 +2333,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2388,8 +2393,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2509,8 +2515,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2624,8 +2631,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2719,8 +2727,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2784,8 +2793,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "origin/master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2891,8 +2901,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "origin/master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -2970,8 +2981,9 @@ mod tests { let project_repository = project_repository::Repository::open(&project)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "origin/master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3055,8 +3067,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "origin/master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3160,8 +3173,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3249,8 +3263,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3419,8 +3434,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "http://origin.com/project".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "http://origin.com/project".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3529,8 +3545,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "http://origin.com/project".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "http://origin.com/project".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3681,8 +3698,9 @@ mod tests { )?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin/master".to_string(), - remote: "http://origin.com/project".to_string(), + remote_name: "origin".to_string(), + branch_name: "master".to_string(), + remote_url: "http://origin.com/project".to_string(), sha: upstream_commit, behind: 0, })?; @@ -3785,8 +3803,9 @@ mod tests { commit_all(&repository)?; target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "origin".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: repository.head().unwrap().target().unwrap(), behind: 0, })?; @@ -3941,8 +3960,9 @@ mod tests { let commit1_oid = repository.head().unwrap().target().unwrap(); let commit1 = repository.find_commit(commit1_oid).unwrap(); target::Writer::new(&gb_repo).write_default(&target::Target { - name: "origin".to_string(), - remote: "origin".to_string(), + branch_name: "master".to_string(), + remote_name: "origin".to_string(), + remote_url: "origin".to_string(), sha: commit1_oid, behind: 0, })?; diff --git a/src-tauri/src/virtual_branches/target/mod.rs b/src-tauri/src/virtual_branches/target/mod.rs index fd47c4bf3..33402ff2b 100644 --- a/src-tauri/src/virtual_branches/target/mod.rs +++ b/src-tauri/src/virtual_branches/target/mod.rs @@ -8,8 +8,9 @@ pub use writer::TargetWriter as Writer; #[derive(Debug, PartialEq, Clone)] pub struct Target { - pub name: String, - pub remote: String, + pub branch_name: String, + pub remote_name: String, + pub remote_url: String, pub sha: git2::Oid, pub behind: u32, } @@ -19,26 +20,56 @@ impl Serialize for Target { where S: Serializer, { - let mut state = serializer.serialize_struct("Target", 3)?; - state.serialize_field("name", &self.name)?; - state.serialize_field("remote", &self.remote)?; + let mut state = serializer.serialize_struct("Target", 5)?; + state.serialize_field("branchName", &self.branch_name)?; + state.serialize_field("remoteName", &self.remote_name)?; + state.serialize_field("remoteUrl", &self.remote_url)?; state.serialize_field("behind", &self.behind)?; state.serialize_field("sha", &self.sha.to_string())?; state.end() } } +// this is a backwards compatibile with the old format +fn read_remote_url(reader: &dyn crate::reader::Reader) -> Result { + match reader.read_string("remote_url") { + Ok(url) => Ok(url), + // fallback to the old format + Err(crate::reader::Error::NotFound) => reader.read_string("remote"), + Err(e) => Err(e), + } +} + +// returns (remote_name, branch_name) +fn read_remote_name_branch_name( + reader: &dyn crate::reader::Reader, +) -> Result<(String, String), crate::reader::Error> { + match reader.read_string("name") { + Ok(branch) => { + let parts = branch.split('/').collect::>(); + Ok((parts[0].to_string(), branch)) + } + Err(crate::reader::Error::NotFound) => { + // fallback to the old format + let remote_name = reader.read_string("remote_name")?; + let branch_name = reader.read_string("branch_name")?; + Ok((remote_name, branch_name)) + } + Err(e) => Err(e), + } +} + impl TryFrom<&dyn crate::reader::Reader> for Target { type Error = crate::reader::Error; fn try_from(reader: &dyn crate::reader::Reader) -> Result { - let name = reader.read_string("name").map_err(|e| { + let (remote_name, branch_name) = read_remote_name_branch_name(reader).map_err(|e| { crate::reader::Error::IOError(std::io::Error::new( std::io::ErrorKind::Other, - format!("name: {}", e), + format!("branch: {}", e), )) })?; - let remote = reader.read_string("remote").map_err(|e| { + let remote_url = read_remote_url(reader).map_err(|e| { crate::reader::Error::IOError(std::io::Error::new( std::io::ErrorKind::Other, format!("remote: {}", e), @@ -61,8 +92,9 @@ impl TryFrom<&dyn crate::reader::Reader> for Target { })?; Ok(Self { - name, - remote, + branch_name, + remote_name, + remote_url, sha, behind: 0, }) diff --git a/src-tauri/src/virtual_branches/target/reader.rs b/src-tauri/src/virtual_branches/target/reader.rs index 0fae625c0..a9c534873 100644 --- a/src-tauri/src/virtual_branches/target/reader.rs +++ b/src-tauri/src/virtual_branches/target/reader.rs @@ -33,6 +33,7 @@ impl<'reader> TargetReader<'reader> { #[cfg(test)] mod tests { + use crate::writer::Writer; use anyhow::Result; use tempfile::tempdir; @@ -116,6 +117,54 @@ mod tests { Ok(()) } + #[test] + fn test_read_deprecated_format() -> Result<()> { + let repository = test_repository()?; + let project = projects::Project::try_from(&repository)?; + let gb_repo_path = tempdir()?.path().to_str().unwrap().to_string(); + let storage = storage::Storage::from_path(tempdir()?.path()); + let user_store = users::Storage::new(storage.clone()); + let project_store = projects::Storage::new(storage); + project_store.add_project(&project)?; + let gb_repo = + gb_repository::Repository::open(gb_repo_path, project.id, project_store, user_store)?; + + let writer = crate::writer::DirWriter::open(gb_repo.root()); + writer + .write_string("branches/target/name", "origin/master") + .unwrap(); + writer + .write_string( + "branches/target/remote", + "git@github.com:gitbutlerapp/gitbutler-client.git", + ) + .unwrap(); + writer + .write_string( + "branches/target/sha", + "dd945831869e9593448aa622fa4342bbfb84813d", + ) + .unwrap(); + + let session = gb_repo.get_or_create_current_session()?; + let session_reader = sessions::Reader::open(&gb_repo, &session)?; + let reader = TargetReader::new(&session_reader); + + let read = reader.read_default().unwrap(); + assert_eq!(read.branch_name, "origin/master"); + assert_eq!(read.remote_name, "origin"); + assert_eq!( + read.remote_url, + "git@github.com:gitbutlerapp/gitbutler-client.git" + ); + assert_eq!( + read.sha, + git2::Oid::from_str("dd945831869e9593448aa622fa4342bbfb84813d").unwrap() + ); + + Ok(()) + } + #[test] fn test_read_override_target() -> Result<()> { let repository = test_repository()?; @@ -131,15 +180,17 @@ mod tests { let branch = test_branch(); let target = Target { - name: "target".to_string(), - remote: "remote".to_string(), + remote_name: "remote".to_string(), + branch_name: "branch".to_string(), + remote_url: "remote url".to_string(), sha: git2::Oid::from_str("fedcba9876543210fedcba9876543210fedcba98").unwrap(), behind: 0, }; let default_target = Target { - name: "default_target".to_string(), - remote: "default_remote".to_string(), + remote_name: "default remote".to_string(), + branch_name: "default branch".to_string(), + remote_url: "default remote url".to_string(), sha: git2::Oid::from_str("0123456789abcdef0123456789abcdef01234567").unwrap(), behind: 0, }; diff --git a/src-tauri/src/virtual_branches/target/writer.rs b/src-tauri/src/virtual_branches/target/writer.rs index 89ecba644..3c823a87b 100644 --- a/src-tauri/src/virtual_branches/target/writer.rs +++ b/src-tauri/src/virtual_branches/target/writer.rs @@ -31,11 +31,14 @@ impl<'writer> TargetWriter<'writer> { } self.writer - .write_string("branches/target/name", &target.name) - .context("Failed to write default target name")?; + .write_string("branches/target/branch_name", &target.branch_name) + .context("Failed to write default target branch name")?; self.writer - .write_string("branches/target/remote", &target.remote) - .context("Failed to write default target remote")?; + .write_string("branches/target/remote_name", &target.remote_name) + .context("Failed to write default target remote name ")?; + self.writer + .write_string("branches/target/remote_url", &target.remote_url) + .context("Failed to write default target remote name ")?; self.writer .write_string("branches/target/sha", &target.sha.to_string()) .context("Failed to write default target sha")?; @@ -53,10 +56,22 @@ impl<'writer> TargetWriter<'writer> { } self.writer - .write_string(&format!("branches/{}/target/name", id), &target.name) - .context("Failed to write branch target name")?; + .write_string( + &format!("branches/{}/target/branch_name", id), + &target.branch_name, + ) + .context("Failed to write branch target branch name")?; self.writer - .write_string(&format!("branches/{}/target/remote", id), &target.remote) + .write_string( + &format!("branches/{}/target/remote_name", id), + &target.remote_name, + ) + .context("Failed to write branch target remote")?; + self.writer + .write_string( + &format!("branches/{}/target/remote_url", id), + &target.remote_url, + ) .context("Failed to write branch target remote")?; self.writer .write_string( @@ -143,8 +158,9 @@ mod tests { let branch = test_branch(); let target = Target { - name: "target_name".to_string(), - remote: "target_remote".to_string(), + branch_name: "branch name".to_string(), + remote_name: "remote name".to_string(), + remote_url: "remote url".to_string(), sha: git2::Oid::from_str("0123456789abcdef0123456789abcdef01234567").unwrap(), behind: 0, }; @@ -163,14 +179,19 @@ mod tests { branch.name ); assert_eq!( - fs::read_to_string(root.join("target").join("name").to_str().unwrap()) + fs::read_to_string(root.join("target").join("branch_name").to_str().unwrap()) .context("Failed to read branch target name")?, - target.name + target.branch_name ); assert_eq!( - fs::read_to_string(root.join("target").join("remote").to_str().unwrap()) - .context("Failed to read branch target remote")?, - target.remote + fs::read_to_string(root.join("target").join("remote_name").to_str().unwrap()) + .context("Failed to read branch target name name")?, + target.remote_name + ); + assert_eq!( + fs::read_to_string(root.join("target").join("remote_url").to_str().unwrap()) + .context("Failed to read branch target remote url")?, + target.remote_url ); assert_eq!( fs::read_to_string(root.join("target").join("sha").to_str().unwrap()) @@ -230,8 +251,9 @@ mod tests { let branch = test_branch(); let target = Target { - name: "target_name".to_string(), - remote: "target_remote".to_string(), + remote_name: "remote name".to_string(), + branch_name: "branch name".to_string(), + remote_url: "remote url".to_string(), sha: git2::Oid::from_str("0123456789abcdef0123456789abcdef01234567").unwrap(), behind: 0, }; @@ -242,8 +264,9 @@ mod tests { target_writer.write(&branch.id, &target)?; let updated_target = Target { - name: "updated_target_name".to_string(), - remote: "updated_target_remote".to_string(), + remote_name: "updated remote name".to_string(), + branch_name: "updated branch name".to_string(), + remote_url: "updated remote url".to_string(), sha: git2::Oid::from_str("fedcba9876543210fedcba9876543210fedcba98").unwrap(), behind: 0, }; @@ -253,14 +276,20 @@ mod tests { let root = gb_repo.root().join("branches").join(&branch.id); assert_eq!( - fs::read_to_string(root.join("target").join("name").to_str().unwrap()) - .context("Failed to read branch target name")?, - updated_target.name + fs::read_to_string(root.join("target").join("branch_name").to_str().unwrap()) + .context("Failed to read branch target branch name")?, + updated_target.branch_name + ); + + assert_eq!( + fs::read_to_string(root.join("target").join("remote_name").to_str().unwrap()) + .context("Failed to read branch target remote name")?, + updated_target.remote_name ); assert_eq!( - fs::read_to_string(root.join("target").join("remote").to_str().unwrap()) - .context("Failed to read branch target remote")?, - updated_target.remote + fs::read_to_string(root.join("target").join("remote_url").to_str().unwrap()) + .context("Failed to read branch target remote url")?, + updated_target.remote_url ); assert_eq!( fs::read_to_string(root.join("target").join("sha").to_str().unwrap()) diff --git a/src-tauri/src/watcher/handlers/project_file_change_tests.rs b/src-tauri/src/watcher/handlers/project_file_change_tests.rs index 4a265bcb2..50b1c2f8d 100644 --- a/src-tauri/src/watcher/handlers/project_file_change_tests.rs +++ b/src-tauri/src/watcher/handlers/project_file_change_tests.rs @@ -12,8 +12,9 @@ static mut TEST_TARGET_INDEX: usize = 0; fn test_target() -> virtual_branches::target::Target { virtual_branches::target::Target { - name: format!("target_name_{}", unsafe { TEST_TARGET_INDEX }), - remote: format!("remote_{}", unsafe { TEST_TARGET_INDEX }), + branch_name: format!("branch name {}", unsafe { TEST_TARGET_INDEX }), + remote_name: format!("remote name {}", unsafe { TEST_TARGET_INDEX }), + remote_url: format!("remote url {}", unsafe { TEST_TARGET_INDEX }), sha: git2::Oid::from_str(&format!( "0123456789abcdef0123456789abcdef0123456{}", unsafe { TEST_TARGET_INDEX } diff --git a/src/lib/vbranches/types.ts b/src/lib/vbranches/types.ts index d2d6f83bd..cfd22c877 100644 --- a/src/lib/vbranches/types.ts +++ b/src/lib/vbranches/types.ts @@ -63,7 +63,8 @@ export class BranchData { export class Target { sha!: string; - name!: string; - remote!: string; + branchName!: string; + remoteName!: string; + remoteUrl!: string; behind!: number; } diff --git a/src/routes/repo/[projectId]/Tray.svelte b/src/routes/repo/[projectId]/Tray.svelte index 5bee79541..13f129222 100644 --- a/src/routes/repo/[projectId]/Tray.svelte +++ b/src/routes/repo/[projectId]/Tray.svelte @@ -69,7 +69,7 @@
    -
    {target.name}
    +
    {target.branchName}
    {target.behind > 0 ? `behind ${target.behind}` : 'up-to-date'}
    From 2034254aae7b5a94ab1617a4d1b3fbffb18b97b9 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Tue, 11 Jul 2023 16:21:04 +0200 Subject: [PATCH 3/4] Remove all "if (building) {}" checks The main problem here was `invoke` being imported from `@tauri-app/api` rather than `@tauri-app/api/tauri`. --- src/hooks.client.ts | 3 +- src/lib/api/cloud/api.ts | 7 ++-- src/lib/components/Login.svelte | 4 +- src/lib/hotkeys.ts | 3 -- src/lib/index.ts | 1 - src/lib/ipc.ts | 11 ++--- src/lib/log.ts | 42 ------------------- src/lib/theme.ts | 2 - src/routes/+error.svelte | 5 +-- src/routes/+layout.ts | 5 +-- .../projects/[projectId]/commit/+page.svelte | 4 +- .../player/[date]/BookmarkModal.svelte | 4 +- .../[projectId]/settings/+page.svelte | 4 +- .../[projectId]/settings/CloudForm.svelte | 4 +- .../projects/[projectId]/terminal/terminal.ts | 3 +- src/routes/user/+page.svelte | 6 +-- 16 files changed, 26 insertions(+), 82 deletions(-) delete mode 100644 src/lib/log.ts diff --git a/src/hooks.client.ts b/src/hooks.client.ts index 2dcd0c6b7..bb8d04f45 100644 --- a/src/hooks.client.ts +++ b/src/hooks.client.ts @@ -1,7 +1,6 @@ import { handleErrorWithSentry, init } from '@sentry/sveltekit'; import type { NavigationEvent } from '@sveltejs/kit'; import { dev } from '$app/environment'; -import { log } from '$lib'; init({ enabled: !dev, @@ -10,7 +9,7 @@ init({ tracesSampleRate: 1.0 }); -log.info(`sentry init`); +console.log(`sentry init`); function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) { console.error('An error occurred on the client side:', error, event); diff --git a/src/lib/api/cloud/api.ts b/src/lib/api/cloud/api.ts index 73a4d644e..f8257b19f 100644 --- a/src/lib/api/cloud/api.ts +++ b/src/lib/api/cloud/api.ts @@ -1,6 +1,5 @@ import { PUBLIC_API_BASE_URL } from '$env/static/public'; import { PUBLIC_CHAIN_API } from '$env/static/public'; -import * as log from '$lib/log'; import { nanoid } from 'nanoid'; const apiUrl = new URL('/api/', new URL(PUBLIC_API_BASE_URL)); @@ -72,13 +71,13 @@ const withRequestId: FetchMiddleware = (fetch) => async (url, options) => { }; const withLog: FetchMiddleware = (fetch) => async (url, options) => { - log.info('fetch', url, options); + console.log('fetch', url, options); try { const resp = await fetch(url, options); - log.info(resp); + console.log(resp); return resp; } catch (e: any) { - log.error('fetch', e); + console.error('fetch', e); throw e; } }; diff --git a/src/lib/components/Login.svelte b/src/lib/components/Login.svelte index 5318a45c9..c95fd9cf5 100644 --- a/src/lib/components/Login.svelte +++ b/src/lib/components/Login.svelte @@ -1,6 +1,6 @@