@@ -61,9 +61,82 @@ struct HistoryInlineRef
6161 bool mIsRemote : 1 ;
6262 bool mIsTag : 1 ;
6363 bool mIsStash : 1 ;
64+ bool mIsDetached : 1 ;
65+
66+ bool operator ==(const HistoryInlineRef& other) const
67+ {
68+ if ( this == &other ) {
69+ return true ;
70+ }
71+
72+ return mRefName == other.mRefName &&
73+ mIsBranch == other.mIsBranch &&
74+ mIsCurrent == other.mIsCurrent &&
75+ mIsRemote == other.mIsRemote &&
76+ mIsTag == other.mIsTag &&
77+ mIsStash == other.mIsStash &&
78+ mIsDetached == other.mIsDetached ;
79+ }
80+
81+ inline bool operator !=(const HistoryInlineRef& other) const {
82+ return !( *this == other );
83+ }
84+
85+ inline bool detachedHEAD () const
86+ {
87+ return mIsDetached && !(mIsTag || mIsBranch || mIsStash );
88+ }
89+
90+ inline bool nameLessThan (const HistoryInlineRef& other) const
91+ {
92+ return mRefName < other.mRefName ;
93+ }
94+
95+ bool operator <(const HistoryInlineRef& other) const
96+ {
97+ // sort order:
98+ // - tag
99+ // - detached HEAD
100+ // - current branch
101+ // - local branch
102+ // - remote branch
103+ // - stash
104+ // - Everything else is sorted by mRefName
105+
106+ if ( mIsTag ) {
107+ // tags have highest priority
108+ return other.mIsTag ? nameLessThan (other) : true ;
109+ }
110+
111+ if ( detachedHEAD () )
112+ {
113+ // a detached HEAD comes right after tag ? -> There can only be one!
114+ return !other.mIsTag ;
115+ }
116+
117+ if ( mIsBranch )
118+ {
119+ if ( other.mIsTag || other.mIsCurrent || other.detachedHEAD () )
120+ return false ;
121+
122+ if ( mIsCurrent ) {
123+ // a is the current branch
124+ return true ;
125+ }
126+
127+ return ( mIsRemote == other.mIsRemote ) ? nameLessThan ( other ) : !mIsRemote ;
128+ }
129+
130+ if ( mIsStash ) {
131+ return other.mIsStash ? nameLessThan ( other )
132+ : !(other.mIsTag || other.mIsBranch || other.detachedHEAD ());
133+ }
134+
135+ return !(other.mIsTag || other.mIsBranch || other.mIsStash || other.detachedHEAD ()) ? nameLessThan ( other ) : false ;
136+ }
64137};
65138
66- typedef QVector < HistoryInlineRef > HistoryInlineRefs;
139+ typedef QList < HistoryInlineRef > HistoryInlineRefs;
67140
68141class HistoryEntry
69142{
0 commit comments