Compare() public static méthode

public static Compare ( DirCacheEntry a, DirCacheEntry b ) : int
a DirCacheEntry
b DirCacheEntry
Résultat int
Exemple #1
0
        private void Resort()
        {
            Array.Sort(Entries, 0, EntryCnt, new GenericComparer <DirCacheEntry>(DirCache.EntryComparer));

            for (int entryIdx = 1; entryIdx < EntryCnt; entryIdx++)
            {
                DirCacheEntry pe = Entries[entryIdx - 1];
                DirCacheEntry ce = Entries[entryIdx];
                int           cr = DirCache.Compare(pe, ce);
                if (cr == 0)
                {
                    // Same file path; we can only allow this if the stages
                    // are 1-3 and no 0 exists.
                    //
                    int peStage = pe.getStage();
                    int ceStage = ce.getStage();

                    if (peStage == ceStage)
                    {
                        throw Bad(ce, "Duplicate stages not allowed");
                    }

                    if (peStage == 0 || ceStage == 0)
                    {
                        throw Bad(ce, "Mixed stages not allowed");
                    }
                }
            }

            _sorted = true;
        }
Exemple #2
0
        private void BeforeAdd(DirCacheEntry newEntry)
        {
            if (FileMode.Tree.Equals(newEntry.getRawMode()))
            {
                throw Bad(newEntry, "Adding subtree not allowed");
            }

            if (_sorted && EntryCnt > 0)
            {
                DirCacheEntry lastEntry = Entries[EntryCnt - 1];
                int           cr        = DirCache.Compare(lastEntry, newEntry);
                if (cr > 0)
                {
                    // The new entry sorts before the old entry; we are
                    // no longer sorted correctly. We'll need to redo
                    // the sorting before we can close out the build.
                    //
                    _sorted = false;
                }
                else if (cr == 0)
                {
                    // Same file path; we can only insert this if the
                    // stages won't be violated.
                    //
                    int peStage  = lastEntry.getStage();
                    int dceStage = newEntry.getStage();
                    if (peStage == dceStage)
                    {
                        throw Bad(newEntry, "Duplicate stages not allowed");
                    }
                    if (peStage == 0 || dceStage == 0)
                    {
                        throw Bad(newEntry, "Mixed stages not allowed");
                    }
                    if (peStage > dceStage)
                    {
                        _sorted = false;
                    }
                }
            }
        }