|
| 1 | +use crate::core::GitReference; |
1 | 2 | use crate::core::PackageId;
|
| 3 | +use crate::core::SourceKind; |
2 | 4 | use crate::sources::registry::CRATES_IO_HTTP_INDEX;
|
3 | 5 | use crate::sources::source::Source;
|
4 | 6 | use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
|
@@ -82,38 +84,6 @@ impl fmt::Display for Precise {
|
82 | 84 | }
|
83 | 85 | }
|
84 | 86 |
|
85 |
| -/// The possible kinds of code source. |
86 |
| -/// Along with [`SourceIdInner`], this fully defines the source. |
87 |
| -#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
88 |
| -pub enum SourceKind { |
89 |
| - /// A git repository. |
90 |
| - Git(GitReference), |
91 |
| - /// A local path. |
92 |
| - Path, |
93 |
| - /// A remote registry. |
94 |
| - Registry, |
95 |
| - /// A sparse registry. |
96 |
| - SparseRegistry, |
97 |
| - /// A local filesystem-based registry. |
98 |
| - LocalRegistry, |
99 |
| - /// A directory-based registry. |
100 |
| - Directory, |
101 |
| -} |
102 |
| - |
103 |
| -/// Information to find a specific commit in a Git repository. |
104 |
| -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
105 |
| -pub enum GitReference { |
106 |
| - /// From a tag. |
107 |
| - Tag(String), |
108 |
| - /// From a branch. |
109 |
| - Branch(String), |
110 |
| - /// From a specific revision. Can be a commit hash (either short or full), |
111 |
| - /// or a named reference like `refs/pull/493/head`. |
112 |
| - Rev(String), |
113 |
| - /// The default branch of the repository, the reference named `HEAD`. |
114 |
| - DefaultBranch, |
115 |
| -} |
116 |
| - |
117 | 87 | /// Where the remote source key is defined.
|
118 | 88 | ///
|
119 | 89 | /// The purpose of this is to provide better diagnostics for different sources of keys.
|
@@ -746,108 +716,6 @@ impl PartialEq for SourceIdInner {
|
746 | 716 | }
|
747 | 717 | }
|
748 | 718 |
|
749 |
| -impl SourceKind { |
750 |
| - pub(crate) fn protocol(&self) -> Option<&str> { |
751 |
| - match self { |
752 |
| - SourceKind::Path => Some("path"), |
753 |
| - SourceKind::Git(_) => Some("git"), |
754 |
| - SourceKind::Registry => Some("registry"), |
755 |
| - // Sparse registry URL already includes the `sparse+` prefix, see `SourceId::new` |
756 |
| - SourceKind::SparseRegistry => None, |
757 |
| - SourceKind::LocalRegistry => Some("local-registry"), |
758 |
| - SourceKind::Directory => Some("directory"), |
759 |
| - } |
760 |
| - } |
761 |
| -} |
762 |
| - |
763 |
| -/// Forwards to `Ord` |
764 |
| -impl PartialOrd for SourceKind { |
765 |
| - fn partial_cmp(&self, other: &SourceKind) -> Option<Ordering> { |
766 |
| - Some(self.cmp(other)) |
767 |
| - } |
768 |
| -} |
769 |
| - |
770 |
| -/// Note that this is specifically not derived on `SourceKind` although the |
771 |
| -/// implementation here is very similar to what it might look like if it were |
772 |
| -/// otherwise derived. |
773 |
| -/// |
774 |
| -/// The reason for this is somewhat obtuse. First of all the hash value of |
775 |
| -/// `SourceKind` makes its way into `~/.cargo/registry/index/github.com-XXXX` |
776 |
| -/// which means that changes to the hash means that all Rust users need to |
777 |
| -/// redownload the crates.io index and all their crates. If possible we strive |
778 |
| -/// to not change this to make this redownloading behavior happen as little as |
779 |
| -/// possible. How is this connected to `Ord` you might ask? That's a good |
780 |
| -/// question! |
781 |
| -/// |
782 |
| -/// Since the beginning of time `SourceKind` has had `#[derive(Hash)]`. It for |
783 |
| -/// the longest time *also* derived the `Ord` and `PartialOrd` traits. In #8522, |
784 |
| -/// however, the implementation of `Ord` changed. This handwritten implementation |
785 |
| -/// forgot to sync itself with the originally derived implementation, namely |
786 |
| -/// placing git dependencies as sorted after all other dependencies instead of |
787 |
| -/// first as before. |
788 |
| -/// |
789 |
| -/// This regression in #8522 (Rust 1.47) went unnoticed. When we switched back |
790 |
| -/// to a derived implementation in #9133 (Rust 1.52 beta) we only then ironically |
791 |
| -/// saw an issue (#9334). In #9334 it was observed that stable Rust at the time |
792 |
| -/// (1.51) was sorting git dependencies last, whereas Rust 1.52 beta would sort |
793 |
| -/// git dependencies first. This is because the `PartialOrd` implementation in |
794 |
| -/// 1.51 used #8522, the buggy implementation, which put git deps last. In 1.52 |
795 |
| -/// it was (unknowingly) restored to the pre-1.47 behavior with git dependencies |
796 |
| -/// first. |
797 |
| -/// |
798 |
| -/// Because the breakage was only witnessed after the original breakage, this |
799 |
| -/// trait implementation is preserving the "broken" behavior. Put a different way: |
800 |
| -/// |
801 |
| -/// * Rust pre-1.47 sorted git deps first. |
802 |
| -/// * Rust 1.47 to Rust 1.51 sorted git deps last, a breaking change (#8522) that |
803 |
| -/// was never noticed. |
804 |
| -/// * Rust 1.52 restored the pre-1.47 behavior (#9133, without knowing it did |
805 |
| -/// so), and breakage was witnessed by actual users due to difference with |
806 |
| -/// 1.51. |
807 |
| -/// * Rust 1.52 (the source as it lives now) was fixed to match the 1.47-1.51 |
808 |
| -/// behavior (#9383), which is now considered intentionally breaking from the |
809 |
| -/// pre-1.47 behavior. |
810 |
| -/// |
811 |
| -/// Note that this was all discovered when Rust 1.53 was in nightly and 1.52 was |
812 |
| -/// in beta. #9133 was in both beta and nightly at the time of discovery. For |
813 |
| -/// 1.52 #9383 reverted #9133, meaning 1.52 is the same as 1.51. On nightly |
814 |
| -/// (1.53) #9397 was created to fix the regression introduced by #9133 relative |
815 |
| -/// to the current stable (1.51). |
816 |
| -/// |
817 |
| -/// That's all a long winded way of saying "it's weird that git deps hash first |
818 |
| -/// and are sorted last, but it's the way it is right now". The author of this |
819 |
| -/// comment chose to handwrite the `Ord` implementation instead of the `Hash` |
820 |
| -/// implementation, but it's only required that at most one of them is |
821 |
| -/// hand-written because the other can be derived. Perhaps one day in |
822 |
| -/// the future someone can figure out how to remove this behavior. |
823 |
| -impl Ord for SourceKind { |
824 |
| - fn cmp(&self, other: &SourceKind) -> Ordering { |
825 |
| - match (self, other) { |
826 |
| - (SourceKind::Path, SourceKind::Path) => Ordering::Equal, |
827 |
| - (SourceKind::Path, _) => Ordering::Less, |
828 |
| - (_, SourceKind::Path) => Ordering::Greater, |
829 |
| - |
830 |
| - (SourceKind::Registry, SourceKind::Registry) => Ordering::Equal, |
831 |
| - (SourceKind::Registry, _) => Ordering::Less, |
832 |
| - (_, SourceKind::Registry) => Ordering::Greater, |
833 |
| - |
834 |
| - (SourceKind::SparseRegistry, SourceKind::SparseRegistry) => Ordering::Equal, |
835 |
| - (SourceKind::SparseRegistry, _) => Ordering::Less, |
836 |
| - (_, SourceKind::SparseRegistry) => Ordering::Greater, |
837 |
| - |
838 |
| - (SourceKind::LocalRegistry, SourceKind::LocalRegistry) => Ordering::Equal, |
839 |
| - (SourceKind::LocalRegistry, _) => Ordering::Less, |
840 |
| - (_, SourceKind::LocalRegistry) => Ordering::Greater, |
841 |
| - |
842 |
| - (SourceKind::Directory, SourceKind::Directory) => Ordering::Equal, |
843 |
| - (SourceKind::Directory, _) => Ordering::Less, |
844 |
| - (_, SourceKind::Directory) => Ordering::Greater, |
845 |
| - |
846 |
| - (SourceKind::Git(a), SourceKind::Git(b)) => a.cmp(b), |
847 |
| - } |
848 |
| - } |
849 |
| -} |
850 |
| - |
851 | 719 | /// A `Display`able view into a `SourceId` that will write it as a url
|
852 | 720 | pub struct SourceIdAsUrl<'a> {
|
853 | 721 | inner: &'a SourceIdInner,
|
@@ -877,73 +745,6 @@ impl<'a> fmt::Display for SourceIdAsUrl<'a> {
|
877 | 745 | }
|
878 | 746 | }
|
879 | 747 |
|
880 |
| -impl GitReference { |
881 |
| - pub fn from_query( |
882 |
| - query_pairs: impl Iterator<Item = (impl AsRef<str>, impl AsRef<str>)>, |
883 |
| - ) -> Self { |
884 |
| - let mut reference = GitReference::DefaultBranch; |
885 |
| - for (k, v) in query_pairs { |
886 |
| - let v = v.as_ref(); |
887 |
| - match k.as_ref() { |
888 |
| - // Map older 'ref' to branch. |
889 |
| - "branch" | "ref" => reference = GitReference::Branch(v.to_owned()), |
890 |
| - |
891 |
| - "rev" => reference = GitReference::Rev(v.to_owned()), |
892 |
| - "tag" => reference = GitReference::Tag(v.to_owned()), |
893 |
| - _ => {} |
894 |
| - } |
895 |
| - } |
896 |
| - reference |
897 |
| - } |
898 |
| - |
899 |
| - /// Returns a `Display`able view of this git reference, or None if using |
900 |
| - /// the head of the default branch |
901 |
| - pub fn pretty_ref(&self, url_encoded: bool) -> Option<PrettyRef<'_>> { |
902 |
| - match self { |
903 |
| - GitReference::DefaultBranch => None, |
904 |
| - _ => Some(PrettyRef { |
905 |
| - inner: self, |
906 |
| - url_encoded, |
907 |
| - }), |
908 |
| - } |
909 |
| - } |
910 |
| -} |
911 |
| - |
912 |
| -/// A git reference that can be `Display`ed |
913 |
| -pub struct PrettyRef<'a> { |
914 |
| - inner: &'a GitReference, |
915 |
| - url_encoded: bool, |
916 |
| -} |
917 |
| - |
918 |
| -impl<'a> fmt::Display for PrettyRef<'a> { |
919 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
920 |
| - let value: &str; |
921 |
| - match self.inner { |
922 |
| - GitReference::Branch(s) => { |
923 |
| - write!(f, "branch=")?; |
924 |
| - value = s; |
925 |
| - } |
926 |
| - GitReference::Tag(s) => { |
927 |
| - write!(f, "tag=")?; |
928 |
| - value = s; |
929 |
| - } |
930 |
| - GitReference::Rev(s) => { |
931 |
| - write!(f, "rev=")?; |
932 |
| - value = s; |
933 |
| - } |
934 |
| - GitReference::DefaultBranch => unreachable!(), |
935 |
| - } |
936 |
| - if self.url_encoded { |
937 |
| - for value in url::form_urlencoded::byte_serialize(value.as_bytes()) { |
938 |
| - write!(f, "{value}")?; |
939 |
| - } |
940 |
| - } else { |
941 |
| - write!(f, "{value}")?; |
942 |
| - } |
943 |
| - Ok(()) |
944 |
| - } |
945 |
| -} |
946 |
| - |
947 | 748 | impl KeyOf {
|
948 | 749 | /// Gets the underlying key.
|
949 | 750 | fn key(&self) -> &str {
|
|
0 commit comments