Comments (23)
Added in da59b1a and ffa2437. Can you verify that these changes are sufficient?
from p5-git-raw.
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.
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.
Adding id
in #186
from p5-git-raw.
5c114d9 adds id
from p5-git-raw.
It would also be useful to provide size
, if it's easily available from the odb.
from p5-git-raw.
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.
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.
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.
Git::Raw::Repository->lookup
will return the specialized object.
from p5-git-raw.
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.
Can you try 61b9a50
from p5-git-raw.
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.
Added (45a4b89)
from p5-git-raw.
data
works fine, thanks.
from p5-git-raw.
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.
Fixed (b155b90)
from p5-git-raw.
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.
Yep, I missed a line :(
from p5-git-raw.
Fixed (fa99da8)
from p5-git-raw.
Everything works perfectly now! Thanks for being so reactive.
I'll now wait for the next release. :-)
from p5-git-raw.
I'll create a release within the next few minutes
from p5-git-raw.
https://metacpan.org/release/JACQUESG/Git-Raw-0.73
from p5-git-raw.
Related Issues (20)
- Add support for commit trailers HOT 4
- -m32 option makes build fail on most 32 bit arches HOT 4
- please make convenience copy of libgit2 et all identifyable HOT 2
- rev-parse support is missing HOT 9
- ppport.h:4594: warning: "WIDEST_UTYPE" redefined HOT 1
- Getting a [-Wstringop-truncation] warning in Walker.xs
- Error during dzil test
- Provide Makefile.PL / cpanfile in git repo HOT 3
- API of Config->set, get to replace str, int, bool HOT 7
- Request: support enumeration and traversal of submodules HOT 6
- Refspec issue with patterns, HOT 4
- libssh2 deprecated in Redhat 7 HOT 2
- Git::Raw::Graph()->is_descendant_of doesn't propagate error codes HOT 1
- Unable to install Git::Raw on AIX 7.2 HOT 1
- Test failure with libgit2-dev 1.3.0 HOT 9
- There are various CVEs for embedded libraries HOT 5
- main vs master HOT 1
- SIGSEGV in test suite
- amending a commit
- does not compile on windows with latest strawberry perl HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p5-git-raw.