Git Product home page Git Product logo

Comments (23)

jacquesg avatar jacquesg commented on May 28, 2024

Added in da59b1a and ffa2437. Can you verify that these changes are sufficient?

from p5-git-raw.

book avatar book commented on May 28, 2024

Here are my various attempts, that mostly produced the expected results:

$ perl -MGit::Raw -E 'Git::Raw::Repository->open(".")->odb->foreach( sub { say $_[0]; return } )'
cc5c34f14d06c688b259a884f15b50f3643f5579
...

And with a slightly longer callback:

$ perl -MGit::Raw -E '
    my $r = Git::Raw::Repository->open(".");
    my @type = qw( bad commit tree blob tag );
    $r->odb->foreach( sub {
        my $id = shift;
        my $o = Git::Raw::Object->lookup( $r, $id );
        say "$id $type[$o->type]";
        return;
    } );
' 
cc5c34f14d06c688b259a884f15b50f3643f5579 commit
...

However, the following code produced an error:

$ perl -Mblib -MGit::Raw -E '
    my $r = Git::Raw::Repository->open(".");
    my @type = qw( bad commit tree blob tag );
    $r->odb->foreach( sub {
        my $id = shift;
        my $o = Git::Raw::Object->lookup( $r, $id );
        say $o->id, " ", $type[$o->type];
        return;
    } );
'
git_pack_foreach_entry callback returned -1

Wrapping the code in an eval block an printing the value of $@ gave:

id is not a valid Git::Raw::Object macro

when $o->id sounded like something I could do.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

You need to return 0 in the callback. A Git::Raw::Object does not currently have an id, but I'll add it.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Adding id in #186

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

5c114d9 adds id

from p5-git-raw.

book avatar book commented on May 28, 2024

It would also be useful to provide size, if it's easily available from the odb.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

This isn't readily available nor do I think it makes sense. What you need I think is

if ($o->type == Git::Raw::Object->BLOB)
{
  my $blob = Git::Raw::Blob->lookup ($repo, $o->id);
  my $size = $blob->size;
  my $content = $blob->content;
}

from p5-git-raw.

book avatar book commented on May 28, 2024

size and content only exist for Git::Raw::Blob, but in the git object database, all object types have a size (and a raw content):

$ git cat-file --batch-check --batch-all-objects | head
0006f34f06abb6f95a27605053db1e48a196d822 tree 2253
0007c41dbca36ec635ab3db392e9fca005b44286 blob 49286
000d754d2f377fd7c21178aa74be1771baf17171 blob 2880
0018ebbf047d549ee2c8ad6cb8a6dc66540a97a5 blob 1190
001eb6d871742b6f41cb296e57d69d9a6e041db6 commit 255
0020a7762899f84ce5d54a7f2bc58a354c62bc2a blob 8497
0023f95ffdc839888f5d9b9a9d54fd7de15ada15 blob 17660
0029c27da0fbcad9ff8b0959bd05d96e72ebced4 tag 147
002a59d751d49a2e5f8ccd4b93cebf172f7e9100 tree 304
002ce43f5a437c432c9216b6d009bb015b6d303f tree 34

from p5-git-raw.

book avatar book commented on May 28, 2024

Also, I was wondering why Git::Raw::Object->lookup didn't return a Perl obect of the right specialized class, instead of the generic (parent?) class.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Git::Raw::Repository->lookup will return the specialized object.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

There does seem to be a way to get the actual size (https://libgit2.github.com/libgit2/#HEAD/group/odb/git_odb_read).

This would require me to add a Git::Raw::Odb::Object

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Can you try 61b9a50

from p5-git-raw.

book avatar book commented on May 28, 2024

Works perfectly! Thanks!

Does the Git::Raw::Odb::Object also give access to the raw object data?
(I assume this is https://libgit2.github.com/libgit2/#HEAD/group/odb/git_odb_object_data).

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Added (45a4b89)

from p5-git-raw.

book avatar book commented on May 28, 2024

data works fine, thanks.

from p5-git-raw.

book avatar book commented on May 28, 2024

I noted that read in Git::Raw::Odb does not work with abbreviated digests. Having the same behaviour as lookup in Git::Raw::Repository would be nice.

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Fixed (b155b90)

from p5-git-raw.

book avatar book commented on May 28, 2024

Thanks!

However, this last patch has an issue, when trying to obtain ambiguous digests:

$ git cat-file --batch-check --batch-all-objects
577ecc210a55a5da10552a4415c4cbb5e321039b blob 988
577eccaacd6343158463f9eaefa19dec78358437 blob 224
65237d4ff8bddefebb2d4801e796f94fa9a9bbeb tree 66
9f0363e979a368db9748fb93278ab91a2152aa71 commit 255
$ perl -MGit::Raw -le '$r=Git::Raw::Repository->open(".");print $r->lookup(shift)' 577ecc
Ambiguous SHA1 prefix - found multiple offsets for pack entry at -e line 1
$ perl -MGit::Raw -le '$r=Git::Raw::Repository->open(".");print $r->odb->read(shift)' 577ecc
Git::Raw::Odb::Object=SCALAR(0x55af77bdeb30)
Segmentation fault

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Yep, I missed a line :(

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

Fixed (fa99da8)

from p5-git-raw.

book avatar book commented on May 28, 2024

Everything works perfectly now! Thanks for being so reactive.

I'll now wait for the next release. :-)

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

I'll create a release within the next few minutes

from p5-git-raw.

jacquesg avatar jacquesg commented on May 28, 2024

https://metacpan.org/release/JACQUESG/Git-Raw-0.73

from p5-git-raw.

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.