Skip to content

Optimize git object parsing with StringScanner#99

Merged
kevmoo merged 1 commit intomasterfrom
scanner_better
Mar 10, 2026
Merged

Optimize git object parsing with StringScanner#99
kevmoo merged 1 commit intomasterfrom
scanner_better

Conversation

@kevmoo
Copy link
Copy Markdown
Owner

@kevmoo kevmoo commented Mar 10, 2026

Migrates custom line-by-line reading logic in tag.dart and commit.dart to use native StringScanner capabilities with multiline regular expressions. This improves parsing robustness and performance.

Fixes handle edge cases including:

  • Parsing multiline headers (e.g., PGP Signatures) correctly.
  • Safely handling missing trailing blank lines and empty message bodies in rev-list outputs.

Migrates custom line-by-line reading logic in `tag.dart` and `commit.dart` to use native `StringScanner` capabilities with multiline regular expressions. This improves parsing robustness and performance.

Fixes handle edge cases including:
- Parsing multiline headers (e.g., PGP Signatures) correctly.
- Safely handling missing trailing blank lines and empty message bodies in rev-list outputs.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the Git object parsing mechanisms, specifically for commits and tags, by replacing manual line-by-line string processing with the more efficient and robust StringScanner library. This change not only improves the performance of parsing operations but also addresses several edge cases related to multiline headers and the structure of Git object messages, leading to more accurate and reliable data extraction.

Highlights

  • Optimized Object Parsing: Migrated custom line-by-line reading logic in tag.dart and commit.dart to leverage native StringScanner capabilities with multiline regular expressions, enhancing parsing efficiency.
  • Improved Robustness: Enhanced parsing robustness, particularly for multiline headers (e.g., PGP Signatures) and edge cases involving missing trailing blank lines or empty message bodies in rev-list outputs.
  • Refactored Regex: Updated the headerRegExp to correctly handle multiline headers by incorporating multiline matching and consuming line endings.
Changelog
  • lib/src/commit.dart
    • Added a check to skip empty lines during commit parsing to prevent errors.
    • Refactored header parsing to use StringScanner.scan with the updated multiline headerRegExp.
    • Introduced logic to explicitly consume the blank line separating headers from the message body.
    • Updated message body parsing for rev-parse output to use StringScanner.scan with a regex that handles message lines and their termination.
  • lib/src/tag.dart
    • Refactored header parsing to use StringScanner.scan with the new multiline headerRegExp.
    • Added a step to consume the blank line that separates tag headers from the message.
  • lib/src/util.dart
    • Removed the StringScanner import as the custom extension is no longer needed.
    • Modified headerRegExp to support multiline header values and ensure it consumes the trailing newline.
    • Removed the StringScannerX extension and its associated _lineRegexp.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully migrates the custom line-by-line parsing logic in tag.dart and commit.dart to leverage the native StringScanner capabilities with multiline regular expressions. This change significantly improves the robustness and performance of parsing Git object data, especially for handling multiline headers and various edge cases related to message bodies and trailing blank lines. The removal of the custom readNextLine extension simplifies the codebase and aligns with the StringScanner's intended usage.

@kevmoo kevmoo merged commit c37874f into master Mar 10, 2026
10 checks passed
@kevmoo kevmoo deleted the scanner_better branch March 10, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant