Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore: Refactor and document GitTreeTranslator#63390

Merged
varungandhi-src merged 3 commits into
mainfrom
vg/gittranslator-refactor
Jun 25, 2024
Merged

chore: Refactor and document GitTreeTranslator#63390
varungandhi-src merged 3 commits into
mainfrom
vg/gittranslator-refactor

Conversation

@varungandhi-src

Copy link
Copy Markdown
Contributor

Previously, the code had several problems:

  • There was code which seemed like it was handling path renames across
    commits, but it was just a no-op. It was not documented why it was
    implemented that way.
  • The Position adjustment API and Range adjustment APIs were inconsistent.
  • The Position and Range adjustment APIs suggested that they could
    handle file renames, but they don't/cannot.
  • The mocking logic was just returning wrong outputs (commits
    instead of paths in one place).

This patch documents the rationale behind the lack of rename handling,
as well as adds a slow-but-correct form of Document checking.

Test plan

Covered by existing tests? 🤷🏽

Changelog

Previously, the code had several problems:
- There was code which seemed like it was handling path renames across
  commits, but it was just a no-op. It was not documented why it was
  implemented that way.
- The Position adjustment API and Range adjustment APIs were inconsistent.
- The Position and Range adjustment APIs suggested that they could
  handle file renames, but they don't/cannot.
- The mocking logic was just returning wrong outputs (commits
  instead of paths in one place).

This patch documents the rationale behind the lack of rename handling,
as well as adds a slow-but-correct form of Document checking.
@cla-bot cla-bot Bot added the cla-signed label Jun 20, 2024
@github-actions github-actions Bot added team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform labels Jun 20, 2024
Comment on lines 11 to 15

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because commits and paths are both strings, this function was meant to return a path as the first return value, and this was just returning a commit, and this was not caught by any of our existing tests.

Comment thread internal/codeintel/codenav/service.go Outdated
Comment on lines 528 to 537

@varungandhi-src varungandhi-src Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly non-ideal, but in the typical case, we don't expect there to be lots of visible uploads (because of the shadowing semantics in the commitgraph logic), and I didn't want to get side-tracked into writing DB queries, this PR has been enough of a distraction already.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make an issue to fix this near-term. Writing a query to do an "EXISTS" rather than fetching the document should (hopefully?) not be too much work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread internal/codeintel/codenav/service.go Outdated

@varungandhi-src varungandhi-src Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case and elsewhere, I'm not 100% sure if we should keep chugging along and return 0 results, but if I were the client, I would likely consider this an error (and wouldn't make requests if I didn't know that precise code intel already existed)

Maybe it's worth having a dedicated error type here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a note to go over these during our next pairing session? Feels like I need to read a lot of code to give a good answer here right now.

@varungandhi-src varungandhi-src force-pushed the vg/gittranslator-refactor branch from 1dec2cb to 30c1767 Compare June 21, 2024 05:33

@kritzcreek kritzcreek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, because I think this is a net-positive over the status-quo.


// NewGitTreeTranslator creates a new GitTreeTranslator with the given repository and source commit.
func NewGitTreeTranslator(client gitserver.Client, args *requestArgs, hunkCache HunkCache) GitTreeTranslator {
func NewGitTreeTranslator(client gitserver.Client, args *translationBase, hunkCache HunkCache) GitTreeTranslator {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename args to base here?

Comment thread internal/codeintel/codenav/service.go Outdated
Comment on lines 528 to 537

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make an issue to fix this near-term. Writing a query to do an "EXISTS" rather than fetching the document should (hopefully?) not be too much work.

Comment thread internal/codeintel/codenav/service.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a note to go over these during our next pairing session? Feels like I need to read a lot of code to give a good answer here right now.

@varungandhi-src varungandhi-src force-pushed the vg/gittranslator-refactor branch from 30c1767 to a9381b5 Compare June 25, 2024 11:32
@varungandhi-src varungandhi-src merged commit ec90be4 into main Jun 25, 2024
@varungandhi-src varungandhi-src deleted the vg/gittranslator-refactor branch June 25, 2024 12:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants