Exemple #1
0
func flatten(r api.Repository, base string, treeEntry *objects.TreeEntry) (result []*objects.TreeEntry, err error) {
	result = make([]*objects.TreeEntry, 0)
	var object objects.Object
	object, err = r.ObjectFromOid(treeEntry.ObjectId())
	if err != nil {
		return nil, err
	}
	tree, _ := object.(*objects.Tree)
	for _, entry := range tree.Entries() {
		result = append(result, objects.NewTreeEntry(entry.Mode(), entry.ObjectType(), base+entry.Name(), entry.ObjectId()))
	}
	return result, nil
}
Exemple #2
0
func compare(a, b *objects.TreeEntry) order {
	if a == b {
		return Same
	}
	if a == nil {
		return Less
	}
	if b == nil {
		return More
	}
	aId, bId := a.ObjectId().String(), b.ObjectId().String()
	if aId < bId {
		return Less
	}
	if aId > bId {
		return More
	}
	return Same
}
Exemple #3
0
func entryKey(entry *objects.TreeEntry, usingMode bool) string {
	key := entry.ObjectId().String() + entry.Name()
	if usingMode {
		key = fmt.Sprintf("%s%d", key, uint16(entry.Mode()))
	}
	return key
}
Exemple #4
0
func (result *TreeDiff) detectModified() {
	var conflated []*TreeEdit
	paths := make(map[string]*TreeEdit)
	uniques := make(map[string]*TreeEdit)
	for _, edit := range result.edits {
		var blob *objects.TreeEntry
		switch edit.action {
		case Insert:
			blob = edit.After
		case Delete:
			blob = edit.Before
		default:
			return
		}
		if existing := paths[blob.Name()]; existing == nil {
			conflated = append(conflated, edit)
			paths[blob.Name()] = edit
			uniques[blob.Name()] = edit
		} else {
			delete(uniques, blob.Name())
			switch existing.action {
			case Insert:
				existing.Before = blob
			case Delete:
				existing.After = blob
			}
			existing.action = Modify
			result.modified = append(result.modified, existing)
		}
	}
	for _, edit := range uniques {
		switch edit.action {
		case Insert:
			result.insertEdits = append(result.insertEdits, edit)
		case Delete:
			result.deleteEdits = append(result.deleteEdits, edit)
		}
	}
	result.edits = conflated
}
Exemple #5
0
func treeFormat(prefix string, te *objects.TreeEntry) string {
	return fmt.Sprintf("%s %s", prefix, te.Name())
}