Пример #1
0
func showVerifyPack(inPack io.ReadSeeker, inIdx io.ReadSeeker) {
	indices, err := go4git.GetAllPackedIndex(inIdx)
	if err != nil {
		panic(err)
	}
	sort.Sort(go4git.ByOffset(indices))
	cnt := len(indices)

	chainLength := make(map[int]int)

	o, err := go4git.ReadPackedObjectAtOffset(int64(indices[0].Offset), inPack, inIdx)
	if err != nil {
		panic(err)
	}
	chainLength[o.RefLevel]++
	for i := 0; i < cnt-1; i++ {
		next, _ := go4git.ReadPackedObjectAtOffset(int64(indices[i+1].Offset), inPack, inIdx)
		if err != nil {
			panic(err)
		}
		chainLength[next.RefLevel]++
		str := fmt.Sprintf("%s %s %d %d %d", go4git.Byte2String(o.Hash), o.ActualType, o.Size, next.StartOffset-o.StartOffset, o.StartOffset)
		if o.Type == go4git.REF_DELTA || o.Type == go4git.OFS_DELTA {
			str += fmt.Sprintf(" %d %s", o.RefLevel, go4git.Byte2String(o.BaseHash))
		}
		fmt.Printf("%s\n", str)
		if go4git.Byte2String(o.Hash) != go4git.Byte2String(indices[i].Hash) {
			panic(fmt.Sprintf("Hash do not match for index %d offset %d in %s: Expected: %s, Computed: %s",
				i,
				indices[i].Offset,
				fileName,
				go4git.Byte2String(indices[i].Hash),
				go4git.Byte2String(o.Hash),
			))
		}
		o = next
		if i == cnt-2 {
			end, _ := inPack.Seek(0, os.SEEK_END)
			end -= 20
			str := fmt.Sprintf("%s %s\t%d %d %d", go4git.Byte2String(next.Hash), next.ActualType, next.Size, end-next.StartOffset, next.StartOffset)
			if o.Type == go4git.REF_DELTA || o.Type == go4git.OFS_DELTA {
				str += fmt.Sprintf(" %d %s", o.RefLevel, go4git.Byte2String(o.BaseHash))
			}
			fmt.Printf("%s\n", str)
		}
	}

	if cnt == 1 {
		end, _ := inPack.Seek(0, os.SEEK_END)
		end -= 20
		str := fmt.Sprintf("%s %s\t%d %d %d", go4git.Byte2String(o.Hash), o.ActualType, o.Size, end-o.StartOffset, o.StartOffset)
		if o.Type == go4git.REF_DELTA || o.Type == go4git.OFS_DELTA {
			str += fmt.Sprintf(" %d %s", o.RefLevel, go4git.Byte2String(o.BaseHash))
		}
		fmt.Printf("%s\n", str)
	}
	showStats(chainLength)
}
Пример #2
0
func showAllIndex(in io.ReadSeeker) {
	indices, err := go4git.GetAllPackedIndex(in)
	if err != nil {
		panic(err)
	}
	for i := 0; i < len(indices); i++ {
		fmt.Fprintf(os.Stdout, "%s\n", indices[i])
	}
}