From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:40
Hello,
Here is my first GSoC series - some work from the last week.
It's actually not a PackWriter, but some changes in existing jgit core
related to PackWriting. Some of these added methods/refactors are not yet
used within this series, but are used in my dirty branch in PackWriter
which is under-development, even somewhat usable.
Series start with formatting stuff, as some old files were not
appropriatelly formatted.
This series is also available at my corechanges branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/corechanges
It's based on Shawn's bsd branch, with new BSD-style license, but I can
rebase if really needed.
If you want to track some PackWriter (itself) development you may want to
have a look at my dirty branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/dirty
That's all. Although Shawn already reviewed some old version of this patches,
I'm still interested in your comments.
Marek Zawirski (12):
Format PackFile class
Format PackIndex class
Format PackIndexV1 class
Add getType() method to RevObject hierarchy
Replace instanceof in WalkFetchConnection with getType()
Move PackFile.SIGNATURE to Constants.PACK_SIGNATURE
Add overload of fromRaw() in MutableObjectId accepting int[]
Copying constructor of MutableObjectId
Add getSize() method to ObjectIdSubclassMap
Add getObjectCount() method to PackFile
Entries iterator in PackIndex and indirectly PackFile
Add PackIndex specific tests, currently only iterators tests
.../tst/org/spearce/jgit/lib/PackIndexTest.java | 152 ++++++++++++++++++++
.../tst/org/spearce/jgit/lib/PackIndexV1Test.java | 54 +++++++
.../tst/org/spearce/jgit/lib/PackIndexV2Test.java | 54 +++++++
...-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 | Bin 0 -> 1296 bytes
...-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 | Bin 0 -> 2976 bytes
.../src/org/spearce/jgit/lib/Constants.java | 8 +
.../src/org/spearce/jgit/lib/MutableObjectId.java | 50 +++++++
.../org/spearce/jgit/lib/ObjectIdSubclassMap.java | 9 ++
.../src/org/spearce/jgit/lib/PackFile.java | 55 +++++--
.../src/org/spearce/jgit/lib/PackIndex.java | 86 +++++++++++-
.../src/org/spearce/jgit/lib/PackIndexV1.java | 45 +++++-
.../src/org/spearce/jgit/lib/PackIndexV2.java | 36 +++++
.../src/org/spearce/jgit/revwalk/RevBlob.java | 6 +
.../src/org/spearce/jgit/revwalk/RevCommit.java | 5 +
.../src/org/spearce/jgit/revwalk/RevObject.java | 8 +
.../src/org/spearce/jgit/revwalk/RevTag.java | 5 +
.../src/org/spearce/jgit/revwalk/RevTree.java | 6 +
.../src/org/spearce/jgit/transport/IndexPack.java | 8 +-
.../jgit/transport/WalkFetchConnection.java | 36 +++--
19 files changed, 576 insertions(+), 47 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
create mode 100644 org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2
create mode 100644 org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2
@@ -58,7 +58,7 @@ public class PackFile {/***Constructareaderforanexisting,pre-indexedpackfile.-*+**@paramparentRepo*Gitrepositoryholdingthispackfile*@paramidxFile
@@ -188,13 +188,11 @@ public class PackFile {if(idx.getObjectCount()!=objectCnt)thrownewIOException("Pack index"+" object count mismatch; expected "+objectCnt-+" found "+idx.getObjectCount()+": "-+pack.getName());++" found "+idx.getObjectCount()+": "+pack.getName());}privatePackedObjectLoaderreader(finalWindowCursorcurs,-finallongobjOffset)-throwsIOException{+finallongobjOffset)throwsIOException{longpos=objOffset;intp=0;finalbyte[]ib=curs.tempId;
@@ -61,7 +61,7 @@ public abstract class PackIndex {*implementationforthatformatwillbeconstructedandreturnedtothe*caller.Thefilemayormaynotbeheldopenbythereturnedinstance.*</p>-*+**@paramidxFile*existingpack.idxtoread.*@returnaccessimplementationfortherequestedfile.
@@ -118,7 +118,7 @@ public abstract class PackIndex {/***Obtainthetotalnumberofobjectsdescribedbythisindex.-*+**@returnnumberofobjectsinthisindex,andlikewiseintheassociated*packthatthisindexwasgeneratedfrom.*/
@@ -126,7 +126,7 @@ public abstract class PackIndex {/***Locatethefileoffsetpositionfortherequestedobject.-*+**@paramobjId*nameoftheobjecttolocatewithinthepack.*@returnoffsetoftheobject'sheaderandcompressedcontent;-1ifthe
@@ -74,6 +74,35 @@ public class MutableObjectId extends AnyObjectId {}/**+*ConvertanObjectIdfrombinaryrepresentationexpressedinintegers.+*+*@paramints+*therawintbuffertoreadfrom.Atleast5integersmustbe+*availablewithinthisintegersarray.+*/+publicvoidfromRaw(finalint[]ints){+fromRaw(ints,0);+}++/**+*ConvertanObjectIdfrombinaryrepresentationexpressedinintegers.+*+*@paramints+*therawintbuffertoreadfrom.Atleast5integersafterp+*mustbeavailablewithinthisintegersarray.+*@paramp+*positiontoreadthefirstintegerofdatafrom.+*+*/+publicvoidfromRaw(finalint[]ints,finalintp){+w1=ints[p];+w2=ints[p+1];+w3=ints[p+2];+w4=ints[p+3];+w5=ints[p+4];+}++/***ConvertanObjectIdfromhexcharacters(US-ASCII).**@parambuf
From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:40
Move to avoid redundancy in reading and writing packfiles in 3 places.
It seems to be a better place for format-related constant.
Signed-off-by: Marek Zawirski <redacted>
---
.../src/org/spearce/jgit/lib/Constants.java | 8 ++++++++
.../src/org/spearce/jgit/lib/PackFile.java | 12 +++++-------
.../src/org/spearce/jgit/transport/IndexPack.java | 8 +++-----
3 files changed, 16 insertions(+), 12 deletions(-)
@@ -188,6 +188,14 @@ public final class Constants {*/publicstaticfinalintOBJ_REF_DELTA=7;+/**+*Packfilesignaturethatoccursatfileheader-identifiesfileasGit+*packfileformatted.+*<p>+*<b>ThisconstantisfixedandisdefinedbytheGitpackfileformat.</b>+*/+publicstaticfinalbyte[]PACK_SIGNATURE={'P','A','C','K'};+/** Native character encoding for commit messages, file names... */publicstaticfinalStringCHARACTER_ENCODING="UTF-8";
@@ -165,17 +163,17 @@ public class PackFile {privatevoidreadPackHeader()throwsIOException{finalWindowCursorcurs=newWindowCursor();longposition=0;-finalbyte[]sig=newbyte[SIGNATURE.length];+finalbyte[]sig=newbyte[Constants.PACK_SIGNATURE.length];finalbyte[]intbuf=newbyte[4];finallongvers;-if(pack.read(position,sig,curs)!=SIGNATURE.length)+if(pack.read(position,sig,curs)!=Constants.PACK_SIGNATURE.length)thrownewIOException("Not a PACK file.");-for(intk=0;k<SIGNATURE.length;k++){-if(sig[k]!=SIGNATURE[k])+for(intk=0;k<Constants.PACK_SIGNATURE.length;k++){+if(sig[k]!=Constants.PACK_SIGNATURE[k])thrownewIOException("Not a PACK file.");}-position+=SIGNATURE.length;+position+=Constants.PACK_SIGNATURE.length;pack.readFully(position,intbuf,curs);vers=NB.decodeUInt32(intbuf,0);
@@ -74,8 +74,6 @@ public class IndexPack {/** Progress message when computing names of delta compressed objects. */publicstaticfinalStringPROGRESS_RESOLVE_DELTA="Resolving deltas";-privatestaticfinalbyte[]SIGNATURE={'P','A','C','K'};-privatestaticfinalintBUFFER_SIZE=2048;/**
@@ -477,10 +475,10 @@ public class IndexPack {}privatevoidreadPackHeader()throwsIOException{-finalinthdrln=SIGNATURE.length+4+4;+finalinthdrln=Constants.PACK_SIGNATURE.length+4+4;finalintp=fillFromInput(hdrln);-for(intk=0;k<SIGNATURE.length;k++)-if(buf[p+k]!=SIGNATURE[k])+for(intk=0;k<Constants.PACK_SIGNATURE.length;k++)+if(buf[p+k]!=Constants.PACK_SIGNATURE[k])thrownewIOException("Not a PACK file.");finallongvers=NB.decodeUInt32(buf,p+4);
@@ -145,6 +145,16 @@ public class PackFile {pack.close();}+/**+*Obtainthetotalnumberofobjectsavailableinthispack.Thismethod+*reliesonpackindex,givingnumberofeffectivelyavailableobjects.+*+*@returnnumberofobjectsinindexofthispack,likewiseinthispack+*/+longgetObjectCount(){+returnidx.getObjectCount();+}+finalUnpackedObjectCache.EntryreadCache(finallongposition){returnUnpackedObjectCache.get(pack,position);}
@@ -251,20 +250,22 @@ class WalkFetchConnection extends FetchConnection {//obj.dispose();-if(objinstanceofRevBlob)-processBlob(obj);--elseif(objinstanceofRevTree)+switch(obj.getType()){+caseConstants.OBJ_BLOB:+processBlob(obj);+break;+caseConstants.OBJ_TREE:processTree(obj);--elseif(objinstanceofRevCommit)+break;+caseConstants.OBJ_COMMIT:processCommit(obj);--elseif(objinstanceofRevTag)+break;+caseConstants.OBJ_TAG:processTag(obj);--else+break;+default:thrownewTransportException("Unknown object type "+obj.getId());+}// If we had any prior errors fetching this object they are// now resolved, as the object was parsed successfully.
@@ -632,19 +633,24 @@ class WalkFetchConnection extends FetchConnection {}privatevoidmarkLocalObjComplete(RevObjectobj)throwsIOException{-while(objinstanceofRevTag){+while(obj.getType()==Constants.OBJ_TAG){obj.add(COMPLETE);obj.dispose();obj=((RevTag)obj).getObject();revWalk.parse(obj);}-if(objinstanceofRevBlob)+switch(obj.getType()){+caseConstants.OBJ_BLOB:obj.add(COMPLETE);-elseif(objinstanceofRevCommit)+break;+caseConstants.OBJ_COMMIT:pushLocalCommit((RevCommit)obj);-elseif(objinstanceofRevTree)+break;+caseConstants.OBJ_TREE:markTreeComplete((RevTree)obj);+break;+}}privatevoidmarkLocalCommitsComplete(finalintuntil)
@@ -107,6 +107,15 @@ public class ObjectIdSubclassMap<V extends ObjectId> {size++;}+/**+*Returnsnumberofobjectsinmap.+*+*@returnnumberofobjectsinmap+*/+publicintsize(){+returnsize;+}+privatefinalintindex(finalAnyObjectIdid){return(id.w1>>>1)%obj_hash.length;}
@@ -38,6 +38,7 @@packageorg.spearce.jgit.revwalk;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;/** A binary file, or a symbolic link. */publicclassRevBlobextendsRevObject{
@@ -55,4 +56,9 @@ public class RevBlob extends RevObject {voidparse(finalRevWalkwalk){flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_BLOB;+}}
@@ -135,6 +135,11 @@ public class RevCommit extends RevObject {buffer=raw;flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_COMMIT;+}staticvoidcarryFlags(RevCommitc,finalintcarry){for(;;){
@@ -42,6 +42,7 @@ import java.io.IOException;importorg.spearce.jgit.errors.IncorrectObjectTypeException;importorg.spearce.jgit.errors.MissingObjectException;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;importorg.spearce.jgit.lib.ObjectId;/** Base object type accessed during revision walking. */
@@ -56,6 +57,13 @@ public abstract class RevObject extends ObjectId {abstractvoidparse(RevWalkwalk)throwsMissingObjectException,IncorrectObjectTypeException,IOException;++/**+*GetGitobjecttype.See{@linkConstants}.+*+*@returnobjecttype+*/+publicabstractintgetType();/***Getthenameofthisobject.
@@ -96,6 +96,11 @@ public class RevTag extends RevObject {flags|=PARSED;}+@Override+publicintgetType(){+returnConstants.OBJ_TAG;+}+/***Parsethistagbufferfordisplay.*
@@ -38,6 +38,7 @@packageorg.spearce.jgit.revwalk;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;/** A reference to a tree of subtrees/files. */publicclassRevTreeextendsRevObject{
@@ -55,4 +56,9 @@ public class RevTree extends RevObject {voidparse(finalRevWalkwalk){flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_TREE;+}}
From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:40
New iterators operate on MutableEntry to achieve high performance.
Information about objects (and its offset) in pack is needed in several
places in original git, and it will be also useful here.
Signed-off-by: Marek Zawirski <redacted>
---
.../src/org/spearce/jgit/lib/PackFile.java | 19 +++++-
.../src/org/spearce/jgit/lib/PackIndex.java | 80 +++++++++++++++++++-
.../src/org/spearce/jgit/lib/PackIndexV1.java | 31 ++++++++
.../src/org/spearce/jgit/lib/PackIndexV2.java | 36 +++++++++
4 files changed, 164 insertions(+), 2 deletions(-)
@@ -146,6 +147,22 @@ public class PackFile {}/**+*Provideiteratoroverentriesinassociatedpackindex,thatshouldalso+*existinthispackfile.Objectsreturnedbysuchiteratoraremutable+*duringiteration.+*<p>+*IteratorreturnsobjectsinSHA-1lexicographicalorder.+*</p>+*+*@returniteratoroverentriesofassociatedpackindex+*+*@seePackIndex#iterator()+*/+publicIterator<PackIndex.MutableEntry>iterator(){+returnidx.iterator();+}++/***Obtainthetotalnumberofobjectsavailableinthispack.Thismethod*reliesonpackindex,givingnumberofeffectivelyavailableobjects.*
@@ -117,6 +119,19 @@ public abstract class PackIndex {}/**+*Provideiteratorthatgivesaccesstoindexentries.Note,thatiterator+*returnsreferencetomutableobject,thesamereferenceineachcall-+*forperformancereason.Ifclientneedsimmutableobjects,itmustcopy+*returnedobjectonitsown.+*<p>+*IteratorreturnsobjectsinSHA-1lexicographicalorder.+*</p>+*+*@returniteratoroverpackindexentries+*/+publicabstractIterator<MutableEntry>iterator();++/***Obtainthetotalnumberofobjectsdescribedbythisindex.**@returnnumberofobjectsinthisindex,andlikewiseintheassociated
@@ -134,4 +149,67 @@ public abstract class PackIndex {*associatedpack.*/abstractlongfindOffset(AnyObjectIdobjId);++/**+*Representmutableentryofpackindexconsistingofobjectidandoffset+*inpack(bothmutable).+*+*/+publicstaticclassMutableEntryextendsMutableObjectId{+privatelongoffset;++/**+*Emptyconstructor.Objectfieldsshouldbefilledinlater.+*/+publicMutableEntry(){+super();+}++/**+*Returnsoffsetforthisindexobjectentry+*+*@returnoffsetofthisobjectinapackfile+*/+publiclonggetOffset(){+returnoffset;+}++voidsetOffset(longoffset){+this.offset=offset;+}++privateMutableEntry(MutableEntrysrc){+super(src);+this.offset=src.offset;+}++/**+*Returnsmutablecopyofthismutableentry.+*+*@returncopyofthismutableentry+*/+publicMutableEntrycloneEntry(){+returnnewMutableEntry(this);+}+}++protectedabstractclassEntriesIteratorimplementsIterator<MutableEntry>{+protectedMutableEntryobjectId=newMutableEntry();++protectedlongreturnedNumber=0;++publicbooleanhasNext(){+returnreturnedNumber<getObjectCount();+}++/**+*Implementationmustupdate{@link#returnedNumber}beforereturning+*element.+*/+publicabstractMutableEntrynext();++publicvoidremove(){+thrownewUnsupportedOperationException();+}+}}
@@ -0,0 +1,152 @@+/*+*Copyright(C)2008,MarekZawirski<marek.zawirski@gmail.com>+*+*Allrightsreserved.+*+*Redistributionanduseinsourceandbinaryforms,withor+*withoutmodification,arepermittedprovidedthatthefollowing+*conditionsaremet:+*+*-Redistributionsofsourcecodemustretaintheabovecopyright+*notice,thislistofconditionsandthefollowingdisclaimer.+*+*-Redistributionsinbinaryformmustreproducetheabove+*copyrightnotice,thislistofconditionsandthefollowing+*disclaimerinthedocumentationand/orothermaterialsprovided+*withthedistribution.+*+*-NeitherthenameoftheGitDevelopmentCommunitynorthe+*namesofitscontributorsmaybeusedtoendorseorpromote+*productsderivedfromthissoftwarewithoutspecificprior+*writtenpermission.+*+*THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSAND+*CONTRIBUTORS"AS IS"ANDANYEXPRESSORIMPLIEDWARRANTIES,+*INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIES+*OFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSE+*AREDISCLAIMED.INNOEVENTSHALLTHECOPYRIGHTOWNEROR+*CONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,+*SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUT+*NOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;+*LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVER+*CAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,+*STRICTLIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)+*ARISINGINANYWAYOUTOFTHEUSEOFTHISSOFTWARE,EVENIF+*ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.+*/++packageorg.spearce.jgit.lib;++importjava.io.File;+importjava.util.Iterator;+importjava.util.NoSuchElementException;++importorg.spearce.jgit.lib.PackIndex.MutableEntry;++publicabstractclassPackIndexTestextendsRepositoryTestCase{++PackIndexsmallIdx;++PackIndexdenseIdx;++publicvoidsetUp()throwsException{+super.setUp();+smallIdx=PackIndex.open(getFileForPack34be9032());+denseIdx=PackIndex.open(getFileForPackdf2982f28());+}++/**+*Returnfilewithappropriateindexversionforpreparedpack.+*+*@returnfilewithindex+*/+publicabstractFilegetFileForPack34be9032();++/**+*Returnfilewithappropriateindexversionforpreparedpack.+*+*@returnfilewithindex+*/+publicabstractFilegetFileForPackdf2982f28();++/**+*TestcontractsofIteratormethodsandthisimplementationremove()+*limitations.+*/+publicvoidtestIteratorMethodsContract(){+Iterator<PackIndex.MutableEntry>iter=smallIdx.iterator();+while(iter.hasNext()){+iter.next();+}++try{+iter.next();+fail("next() unexpectedly returned element");+}catch(NoSuchElementExceptionx){+// expected+}++try{+iter.remove();+fail("remove() shouldn't be implemented");+}catch(UnsupportedOperationExceptionx){+// expected+}+}++/**+*Testresultsofiteratorcomparingtocontentofwell-known(prepared)+*smallindex.+*/+publicvoidtestIteratorReturnedValues1(){+Iterator<PackIndex.MutableEntry>iter=smallIdx.iterator();+assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",iter.next()+.toString());+assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab",iter.next()+.toString());+assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259",iter.next()+.toString());+assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3",iter.next()+.toString());+assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7",iter.next()+.toString());+assertEquals("902d5476fa249b7abc9d84c611577a81381f0327",iter.next()+.toString());+assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035",iter.next()+.toString());+assertEquals("c59759f143fb1fe21c197981df75a7ee00290799",iter.next()+.toString());+assertFalse(iter.hasNext());+}++/**+*CompareoffsetfromiteratorentrieswithoutputoffindOffset()method.+*/+publicvoidtestCompareEntriesOffsetsWithFindOffsets(){+for(MutableEntryme:smallIdx){+assertEquals(smallIdx.findOffset(me),me.getOffset());+}+for(MutableEntryme:denseIdx){+assertEquals(denseIdx.findOffset(me),me.getOffset());+}+}++/**+*Testpartialresultsofiteratorcomparingtocontentofwell-known+*(prepared)denseindex,thatmayneedmulti-levelindexing.+*/+publicvoidtestIteratorReturnedValues2(){+Iterator<PackIndex.MutableEntry>iter=denseIdx.iterator();+while(!iter.next().toString().equals(+"0a3d7772488b6b106fb62813c4d6d627918d9181")){+// just iterating+}+assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3",iter.next()+.toString());// same level-1+assertEquals("10da5895682013006950e7da534b705252b03be6",iter.next()+.toString());// same level-1+assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",iter.next()+.toString());+}++}
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:40
Hi,
On Mon, 2 Jun 2008, Marek Zawirski wrote:
Series start with formatting stuff, as some old files were not
appropriatelly formatted.
You mean line-wrapping, right? Is there a different
recommended column/line ratio for JGit than for Git? Because some of your
later patches introduce lines longer than 80 columns/line.
Add getType() method to RevObject hierarchy
Was the idea not to use instanceof to be able to have multiple "types" per
object? I.e. a commit object is of type commit, but also of type
object...
BTW I really like the iterator implementation.
Ciao,
Dscho
From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:40
Johannes Schindelin wrote:
(...)
You mean line-wrapping, right? Is there a different
recommended column/line ratio for JGit than for Git? Because some of your
later patches introduce lines longer than 80 columns/line.
Not only line-wrapping in fact. egit/jgit use it's own eclipse formatting template
that define more than line-wrapping, even some spaces in javadocs as you may have seen.
Actually I don't know is it 80 columns/line (but I suspect it may be), as I just use
this formatter associated with project by simply pressing some keyboard shortcut.
Maybe I simply missed some formatting, which patch do you mean? Some things however
look strange after auto-formatting. While it may even look ugly for somebody I
wouldn't try to change that by hand, to make other commiters lifes easier allowing
them also just press "format" button ;)
quoted
Add getType() method to RevObject hierarchy
Was the idea not to use instanceof to be able to have multiple "types" per
object? I.e. a commit object is of type commit, but also of type
object...
I'm not sure whether I understand you, but probably it was not what you mean. The
only idea behind that was to refactor instanceofs to polymorphic getType() calls. It
allows us mapping, indexing by type, using switches... without tones of code.
BTW I really like the iterator implementation.
Thanks for looking in.
--
Marek Zawirski [zawir]
marek.zawirski@gmail.com
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:40
Hi,
On Tue, 3 Jun 2008, Marek Zawirski wrote:
Johannes Schindelin wrote:
(...)
quoted
You mean line-wrapping, right? Is there a different recommended
column/line ratio for JGit than for Git? Because some of your later
patches introduce lines longer than 80 columns/line.
Not only line-wrapping in fact. egit/jgit use it's own eclipse
formatting template that define more than line-wrapping, even some
spaces in javadocs as you may have seen.
Actually I don't know is it 80 columns/line (but I suspect it may be),
as I just use this formatter associated with project by simply pressing
some keyboard shortcut. Maybe I simply missed some formatting, which
patch do you mean? Some things however look strange after
auto-formatting. While it may even look ugly for somebody I wouldn't try
to change that by hand, to make other commiters lifes easier allowing
them also just press "format" button ;)
Ah, thanks for the explanation!
quoted
quoted
Add getType() method to RevObject hierarchy
Was the idea not to use instanceof to be able to have multiple "types"
per object? I.e. a commit object is of type commit, but also of type
object...
I'm not sure whether I understand you, but probably it was not what you
mean. The only idea behind that was to refactor instanceofs to
polymorphic getType() calls.
Actually, the result is no longer polymorphic, as every object can have
only one type now.
It allows us mapping, indexing by type, using switches... without tones
of code.
Hrm, I thought that you added more lines than you deleted. But hey, I do
not really know what you want to index, maybe you got a point there. I
guess I'll see ;-)
Ciao,
Dscho
From: Robin Rosenberg <hidden> Date: 2016-06-15 22:44:42
måndagen den 2 juni 2008 23.24.31 skrev Marek Zawirski:
Hello,
Here is my first GSoC series - some work from the last week.
It's actually not a PackWriter, but some changes in existing jgit core
related to PackWriting. Some of these added methods/refactors are not yet
used within this series, but are used in my dirty branch in PackWriter
which is under-development, even somewhat usable.
Series start with formatting stuff, as some old files were not
appropriatelly formatted.
This series is also available at my corechanges branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/corechanges
It's based on Shawn's bsd branch, with new BSD-style license, but I can
rebase if really needed.
No, that's fine.
If you want to track some PackWriter (itself) development you may want to
have a look at my dirty branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/dirty
That's all. Although Shawn already reviewed some old version of this patches,
I'm still interested in your comments.
A well defined set of enhancements with only minor nitpicks (in separate mails) I'm somewhat reluctant to reformatting patches though. Ideally we'd be using eclipse 3.4 and have it format changed parts automatically on save (or similar feature for other IDE's). I tried format on all classes leading to 118 files changed, but nothing major, just a lot of changes with no relevant to readability, except some cases which only made things worse. That's a reason why I have not formatted code according to settings, although
the most common reason is probably sloppiness.
-- robin
@@ -107,6 +107,15 @@ public class ObjectIdSubclassMap<V extends ObjectId> {size++;}+/**+*Returnsnumberofobjectsinmap.+*+*@returnnumberofobjectsinmap+*/+publicintsize(){+returnsize;+}
Just the @return is usually enough for methods that simply return a value. If you
have both the untagged part of the comment should explain much more. Patch
10 is a good example.
-- robin
From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:42
On Fri, Jun 6, 2008 at 3:24 PM, Robin Rosenberg
[off-list ref] wrote:
A well defined set of enhancements with only minor nitpicks (in separate mails)
Nice to hear. I'll send v2 of these 2 patches (04 and 09) in a moment.
With a slightly less place for nitpicks, I hope.
I'm somewhat reluctant to reformatting patches though.
Well, so should I remove these reformatting patches from series? (oouch!)
Actually, when I ran into formatting problem, Shawn suggested that I may
format PackFile as he was also touching this file - I much appreciated
this idea. PackIndex* formatting is however my own invention.
So you assume that Eclipse 3.4 will just force us to submit new patches
with specified formatting, but keep old lines formatting untouched, am I
right?
Isn't it somewhat annoying that formatting is inconsistent through
project (especially line width in some places)? And that I almost have
to block formatting shortcut to stop my pre-save/pre-commit habit?;)
Thanks,
--
Marek Zawirski / zawir
marek.zawirski@gmail.com
From: Marek Zawirski <hidden> Date: 2016-06-15 22:44:42
Introduce natural correlation between each concrete RevObject and
existing integer (constant) for that object type. Such an integer
allows us reducing code amount to perform indexing array by type
or mapping by type. We can also use switches instead of instanceof
or write output type directly.
We could have a common code with behavior determined by polymorphic
getType() call.
Signed-off-by: Marek Zawirski <redacted>
---
.../src/org/spearce/jgit/revwalk/RevBlob.java | 6 ++++++
.../src/org/spearce/jgit/revwalk/RevCommit.java | 5 +++++
.../src/org/spearce/jgit/revwalk/RevObject.java | 8 ++++++++
.../src/org/spearce/jgit/revwalk/RevTag.java | 5 +++++
.../src/org/spearce/jgit/revwalk/RevTree.java | 6 ++++++
5 files changed, 30 insertions(+), 0 deletions(-)
@@ -38,6 +38,7 @@packageorg.spearce.jgit.revwalk;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;/** A binary file, or a symbolic link. */publicclassRevBlobextendsRevObject{
@@ -55,4 +56,9 @@ public class RevBlob extends RevObject {voidparse(finalRevWalkwalk){flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_BLOB;+}}
@@ -135,6 +135,11 @@ public class RevCommit extends RevObject {buffer=raw;flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_COMMIT;+}staticvoidcarryFlags(RevCommitc,finalintcarry){for(;;){
@@ -42,6 +42,7 @@ import java.io.IOException;importorg.spearce.jgit.errors.IncorrectObjectTypeException;importorg.spearce.jgit.errors.MissingObjectException;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;importorg.spearce.jgit.lib.ObjectId;/** Base object type accessed during revision walking. */
@@ -56,6 +57,13 @@ public abstract class RevObject extends ObjectId {abstractvoidparse(RevWalkwalk)throwsMissingObjectException,IncorrectObjectTypeException,IOException;++/**+*GetGitobjecttype.See{@linkConstants}.+*+*@returnobjecttype+*/+publicabstractintgetType();/***Getthenameofthisobject.
@@ -96,6 +96,11 @@ public class RevTag extends RevObject {flags|=PARSED;}+@Override+publicintgetType(){+returnConstants.OBJ_TAG;+}+/***Parsethistagbufferfordisplay.*
@@ -38,6 +38,7 @@packageorg.spearce.jgit.revwalk;importorg.spearce.jgit.lib.AnyObjectId;+importorg.spearce.jgit.lib.Constants;/** A reference to a tree of subtrees/files. */publicclassRevTreeextendsRevObject{
@@ -55,4 +56,9 @@ public class RevTree extends RevObject {voidparse(finalRevWalkwalk){flags|=PARSED;}++@Override+publicintgetType(){+returnConstants.OBJ_TREE;+}}
@@ -107,6 +107,13 @@ public class ObjectIdSubclassMap<V extends ObjectId> {size++;}+/**+*@returnnumberofobjectsinmap+*/+publicintsize(){+returnsize;+}+privatefinalintindex(finalAnyObjectIdid){return(id.w1>>>1)%obj_hash.length;}
From: Shawn O. Pearce <hidden> Date: 2016-06-15 22:44:42
Marek Zawirski [off-list ref] wrote:
On Fri, Jun 6, 2008 at 3:24 PM, Robin Rosenberg
quoted
I'm somewhat reluctant to reformatting patches though.
Well, so should I remove these reformatting patches from series? (oouch!)
Actually, when I ran into formatting problem, Shawn suggested that I may
format PackFile as he was also touching this file - I much appreciated
this idea. PackIndex* formatting is however my own invention.
I'm in favor of reformatting, at least these two classes.
Editing them without the formatting fixes is insanely annoying.
But bulk reformatting all 118 files at once is nuts.
I'd rather do it one file at a time, when we touch it, and especially
if it is fairly stable and isn't being actively hacked on by others.
Isn't it somewhat annoying that formatting is inconsistent through
project (especially line width in some places)? And that I almost have
to block formatting shortcut to stop my pre-save/pre-commit habit?;)
From: Robin Rosenberg <hidden> Date: 2016-06-15 22:44:43
måndagen den 2 juni 2008 23.24.31 skrev Marek Zawirski:
Hello,
Here is my first GSoC series - some work from the last week.
It's actually not a PackWriter, but some changes in existing jgit core
related to PackWriting. Some of these added methods/refactors are not yet
used within this series, but are used in my dirty branch in PackWriter
which is under-development, even somewhat usable.
Series start with formatting stuff, as some old files were not
appropriatelly formatted.
This series is also available at my corechanges branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/corechanges
It's based on Shawn's bsd branch, with new BSD-style license, but I can
rebase if really needed.
If you want to track some PackWriter (itself) development you may want to
have a look at my dirty branch:
http://repo.or.cz/w/egit/zawir.git?a=shortlog;h=refs/heads/dirty
That's all. Although Shawn already reviewed some old version of this patches,
I'm still interested in your comments.
This patchset is in master (merged)
Thanks.
-- robin