Coder Social home page Coder Social logo

Comments (1)

Byron avatar Byron commented on May 25, 2024

Insights gained

All the time the trait I was looking for was Borrow. The current implementation that enforces Owned and Borrowed versions of the same thing are me trying to poorly emulate what AsRef<> could do, with the difference that Borrow<> will take ownership if you let it (along with possibly instantiating huge functions/methods.

Thus we should do the following:

  • Remove git_object::(borrowed|owned)::Id and HashKind as these lead to people depending on git_object instead of git_hash (like happed with git-commitgraph)
  • Find a way to have multi-length borrowed Ids (as slice) and use the fact that the length of a hash digest encodes its type. It's likely these will only grow so we should be safe for a while. Effectively, this is relevant for borrowed::Tree, so we might even keep the code there and greatly simplify git-hash (pushing some of the code into git-object). Conversions from owned Ids to borrowed ones are cheap, the other way around involves a copy. It's also relevant for all zero-copy return values of hashes.
    • The type ideally is properly borrowed, such as in &borrowed::Id, which enables ToOwned traits and Borrow to be used properly.
  • Receivers of borrowed hashes that are public facing should use impl Borrow<hash::Id> for convenience, internal receivers should use plain references. Avoid putting generics into receivers with lots of code but instead use 'landing pads'.
    • Review crates to find refactoring opportunities. There is great benefit in having zero-copy object Ids and there is no way to remove them from the equation. However, they should just be slices, see the next point. Maybe make it easy to use owned Ids as borrowed ones.
      • git-commitgraph lookup
      • git-object
      • git-odb::*::locate()
  • Unify name to be Id everywhere.
  • Add Sha256 support for good measure (it should be representable in the type system, not working for everything), assure that adding it actually works as anticipated. It' not the time yet, see comment at bb24dc4
  • Rename git_hash::Oid to git_hash::ObjectId and git_hash::borrowed::Id to git_hash::oid 🎉
  • Make ObjectId and oid comparable (Eq, Ord) for convenience, remove 'as_ref()' where it was added because of these missing

Then republish these crates with breaking changes:

  • git-features (git-hash in public interface)
  • git-hash (rename)
  • git-object (less public export)
  • git-odb
  • git-commitgraph (use git-hash)
  • git-protocol
  • gitoxide-core

Correction

When looking at how git_hash::Borrowed is actually used it's clear these are for keeping them in fields of structures, which seemed impossible to do with git_hash::Owned() - let's test more.

This usage as field is in exactly one spot: Tree::entries refers to a vector of borrowed name/bin-hash-id . Packs for instance can be created from readers and thus copy the hash's bytes (there is no buffer to reference), or from a byte buffer, but the API ops to always copy the bytes instead of referencing them. It's a potential optimization which probably isn't worth it as these deltas are only used in thin packs. So the verdict remains: all the fuzz about Owned and Borrowed hashes is merely for one use in the deserialized zero copy Tree.

from gitoxide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.