예제 #1
0
        /// <summary>
        /// add a new item to the queue
        /// </summary>
        internal void push(int id, Item itm, int distance)
        {
            QueryRec rec = new QueryRec
            {
                id       = id,
                item     = itm,
                distance = distance,
            };

            _queries.push(rec);
        }
예제 #2
0
        private void _qm_worker(object arg)
        {
            bool      done = false;
            Changeset cs   = null;

            while (!done)
            {
                bool signaled = _queries.ItemsWaiting.WaitOne(100);

                if (signaled)
                {
                    QueryRec rec = _queries.pop();

                    if (rec != null)
                    {
                        cs = _megahist.getCS(rec.id);

                        /* run the query. */
                        IList <QueryRec> recs = _megahist.queryMerge(cs, rec.item, rec.distance);

                        /* dump the extra queries into the queue */
                        foreach (var r in recs)
                        {
                            _queries.push(r);
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
                else
                {
                    done = true;
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        /// <param name="targetItem"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public IList <QueryRec> queryMerge(Changeset cs, Item targetItem, int distance)
        {
            string                srcPath   = null;
            VersionSpec           srcVer    = null;
            int                   srcDelID  = 0;
            VersionSpec           targetVer = new ChangesetVersionSpec(cs.ChangesetId);
            VersionSpec           fromVer   = targetVer;
            VersionSpec           toVer     = targetVer;
            RecursionType         recurType = RecursionType.None;     /* assume these are all files */
            ChangesetMergeDetails mergedetails;
            Revision              revision;

            ChangesetDict_T visitedItems;

            /* map a changeset id to a list of items in that changeset which were merged.
             * (that we happen to care about.
             */

            /* don't do queries when we've reached the distance limit. */
            if (distance == 0)
            {
                return(new List <QueryRec>());
            }

            if (targetItem.ItemType != ItemType.File)
            {
                recurType = RecursionType.Full;
            }

            Logger.logger.DebugFormat("qm[{0},{1},{2},{3},{4},{5},{6},{7},{8}]",
                                      (srcPath == null ? "(null)" : srcPath),
                                      (srcVer == null ? "(null)"  : srcVer.DisplayString), srcDelID,
                                      targetItem.ServerItem, targetVer.DisplayString, targetItem.DeletionId,
                                      fromVer.DisplayString, toVer.DisplayString, recurType);


            saastdlib.Timer t = new saastdlib.Timer();
            t.start();
            mergedetails =
                _vcs.QueryMergesWithDetails(srcPath, srcVer, srcDelID,
                                            targetItem.ServerItem, targetVer,
                                            targetItem.DeletionId,
                                            fromVer, toVer, recurType);
            t.stop();

            lock (_qt)
            {
                ++_qc;
                _qt.TotalT += t.DeltaT;

                if (t.DeltaT > _qtm)
                {
                    _qtm = t.DeltaT;
                }
            }
            t = null;

            visitedItems = _processDetails(cs.ChangesetId, mergedetails);

            {
                string itemPath = targetItem.ServerItem;
                if (targetItem.ItemType != ItemType.File)
                {
                    itemPath += '/';
                }

                Logger.logger.DebugFormat("v[{0}{1}]", itemPath, cs.ChangesetId);
                revision = _results.construct(itemPath, cs);
            }

            /* now walk the list of compiled changesetid + itempath and
             * construct a versioned item for each that we can actually go and query.
             */
            List <QueryRec> items = new List <QueryRec>();

            for (ChangesetDict_T.iterator it = visitedItems.begin();
                 it != visitedItems.end();
                 ++it)
            {
                Item itm = null;
                SortedPaths_T.iterator pathsIt = it.value().begin();

                revision.addParent(it.item());

                if ((distance - 1) > 0)
                {
                    /* only query the item info if we're going to do a query on it. */

                    if (it.value().size() > 1)
                    {
                        /* so, find out what this branch is and use the changeset id. */
                        string thisBranch = tfsinterface.Utils.GetEGSBranch(pathsIt.item());
                        string pathPart   = tfsinterface.Utils.GetPathPart(targetItem.ServerItem);

                        //Console.WriteLine("---- {0} => {1} + {2}", pair.Value.Values[0], thisBranch, pathPart);
                        if (!string.IsNullOrEmpty(thisBranch))
                        {
                            Logger.logger.DebugFormat("iqm[{0},{1}]",
                                                      thisBranch + "/EGS/" + pathPart,
                                                      it.item());

                            itm = _getItem(thisBranch + "/EGS/" + pathPart,
                                           it.item(), 0, false);
                        }
                        else
                        {
                            System.Console.WriteLine("---[e] {0}", pathsIt.item());
                        }
                    }
                    else
                    {
                        /* so, this is the only file we noticed for this changeset,
                         * spawn a new query for just this file (folder?)
                         */

                        Logger.logger.DebugFormat("iq1[{0},{1}]", pathsIt.item(), it.item());

                        try {
                            itm = _getItem(pathsIt.item(), it.item(), 0, false);
                        } catch (System.Exception ex)
                        {
                            Logger.logger.Fatal("fatal item query:", ex);

                            try {
                                /* try just the path, i doubt this will work either, but *shrug* */
                                itm = _getItem(pathsIt.item());
                            } catch (System.Exception) { itm = null; }
                        }
                    }

                    /* queue it. */
                    if (itm != null)
                    {
                        if (!_results.visited(it.item()))
                        {
                            QueryRec rec = new QueryRec
                            {
                                id       = it.item(),
                                item     = itm,
                                distance = (distance - 1),
                            };

                            items.Add(rec);
                        }
                    }
                }
            }

            return(items);
        }