comparison rust/hg-core/src/revlog/index.rs @ 52045:652149ed64f0

rust: improve `InvalidRevision` error message I encountered this when debugging earlier and felt like we were losing some information along the way, which we were!
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 01 Oct 2024 13:20:40 +0200
parents 609700e5d8df
children f2eab4967bfc
comparison
equal deleted inserted replaced
52044:0cd16b1d613f 52045:652149ed64f0
827 if base == NULL_REVISION.0 { 827 if base == NULL_REVISION.0 {
828 return Ok(true); 828 return Ok(true);
829 } 829 }
830 let [mut p1, mut p2] = self 830 let [mut p1, mut p2] = self
831 .parents(rev) 831 .parents(rev)
832 .map_err(|_| RevlogError::InvalidRevision)?; 832 .map_err(|e| RevlogError::InvalidRevision(e.to_string()))?;
833 while let Some(p1_entry) = self.get_entry(p1) { 833 while let Some(p1_entry) = self.get_entry(p1) {
834 if p1_entry.compressed_len() != 0 || p1.0 == 0 { 834 if p1_entry.compressed_len() != 0 || p1.0 == 0 {
835 break; 835 break;
836 } 836 }
837 let parent_base = 837 let parent_base =
838 p1_entry.base_revision_or_base_of_delta_chain(); 838 p1_entry.base_revision_or_base_of_delta_chain();
839 if parent_base.0 == p1.0 { 839 if parent_base.0 == p1.0 {
840 break; 840 break;
841 } 841 }
842 p1 = self 842 p1 = self.check_revision(parent_base).ok_or(
843 .check_revision(parent_base) 843 RevlogError::InvalidRevision(parent_base.to_string()),
844 .ok_or(RevlogError::InvalidRevision)?; 844 )?;
845 } 845 }
846 while let Some(p2_entry) = self.get_entry(p2) { 846 while let Some(p2_entry) = self.get_entry(p2) {
847 if p2_entry.compressed_len() != 0 || p2.0 == 0 { 847 if p2_entry.compressed_len() != 0 || p2.0 == 0 {
848 break; 848 break;
849 } 849 }
850 let parent_base = 850 let parent_base =
851 p2_entry.base_revision_or_base_of_delta_chain(); 851 p2_entry.base_revision_or_base_of_delta_chain();
852 if parent_base.0 == p2.0 { 852 if parent_base.0 == p2.0 {
853 break; 853 break;
854 } 854 }
855 p2 = self 855 p2 = self.check_revision(parent_base).ok_or(
856 .check_revision(parent_base) 856 RevlogError::InvalidRevision(parent_base.to_string()),
857 .ok_or(RevlogError::InvalidRevision)?; 857 )?;
858 } 858 }
859 if base == p1.0 || base == p2.0 { 859 if base == p1.0 || base == p2.0 {
860 return Ok(false); 860 return Ok(false);
861 } 861 }
862 rev = self 862 rev = self
863 .check_revision(base.into()) 863 .check_revision(base.into())
864 .ok_or(RevlogError::InvalidRevision)?; 864 .ok_or(RevlogError::InvalidRevision(base.to_string()))?;
865 } 865 }
866 Ok(rev == NULL_REVISION) 866 Ok(rev == NULL_REVISION)
867 } 867 }
868 868
869 /// Return whether the given revision is a snapshot. Returns an error if 869 /// Return whether the given revision is a snapshot. Returns an error if