Minecraft wiki entry for Before_1.8, associated text: The target will be repaired, adding the durability of the sacrifice plus a bonus, up to the item's maximum durability. If the target item is undamaged, there will be no charge for repair.
It also tries to combine the sacrifice's enchantments onto the target. If the sacrifice has no enchantments, or only weaker versions of the target's enchantments, then there will be no charge. Otherwise, you will pay for enchantments added, and for some cases where the transfer fails (see below). For each enchantment on the sacrifice:
If the target has the enchantment as well...
and the sacrifice level is greater, the target will be raised to the sacrifice's level.
and the sacrifice level is equal, the target gains one level, unless it is already at the maximum level for that enchantment.
and the sacrifice level is less, nothing changes on the target.
If the target does not have the enchantment, it will gain all levels of that enchantment, unless it already has an incompatible enchantment. Enchantments are incompatible if both are in one of the following groups:
Sword: Sharpness, Smite, and Bane of Arthropods
Tool: Fortune and Silk Touch
Armor: Protection, Fire Protection, Projectile Protection, and Blast Protection