示例#1
0
        /// <summary>
        /// Load test cases
        /// </summary>
        /// <param name="testcasePath">Test case location</param>
        /// <param name="number">Test case index</param>
        /// <param name="filePath">Location of C++ file related to the conflict</param>
        /// <returns>Returns a merge conflict object containing the conflict related information</returns>
        public static MergeConflict LoadTestInput(string testcasePath, string number, string filePath)
        {
            string conflict    = testcasePath + number + "_Conflict.txt";
            string content     = testcasePath + number + "_FileName.txt";
            string fileContent = null;
            int    type        = conflictType(conflict);

            if (File.Exists(content))
            {
                content     = System.IO.File.ReadAllText(@content);
                fileContent = filePath + content;
            }
            if (File.Exists(fileContent))
            {
                fileContent = System.IO.File.ReadAllText(@fileContent);
            }
            else
            {
                fileContent = null;
            }
            conflict = System.IO.File.ReadAllText(@conflict);
            MergeConflict input = new MergeConflict(conflict, fileContent, "", type);

            return(input);
        }
示例#2
0
            public static MergeConflict ToMergeConflict(JProperty prop)
            {
                var res = new MergeConflict();

                res.fieldName = prop.Name;
                if (prop.Value is JObject o)
                {
                    var properties = o.Properties();
                    if (IsArray(properties.First()))
                    {
                        res.specialType = MergeConflict.SPECIAL_TYPE_ARRAY;
                        properties      = properties.Skip(1);
                    }
                    res.conflicts = properties.Map(ToMergeConflict);
                }
                else if (prop.Value is JArray oldAndNewValue)
                {
                    AssertV2.AreEqual(2, oldAndNewValue.Count);
                    res.oldValue = oldAndNewValue[0];
                    res.newValue = oldAndNewValue[1];
                }
                else
                {
                    throw new NotImplementedException("Unhandled type " + prop.Value.GetType() + ":\n" + prop.Value.ToPrettyString());
                }
                return(res);
            }
示例#3
0
        /// <summary>
        /// Read the conflict resolution done by the user
        /// </summary>
        /// <param name="Path">Location of the resolved path</param>
        /// <param name="type">1=include, 2=macro related conflicts</param>
        /// <returns>List of nodes of resolved conflicts</returns>
        public static IReadOnlyList <Node> readResolvedConflicts(string Path, int type)
        {
            string resolvedConflict = System.IO.File.ReadAllText(@Path);

            if (type == 1)
            {
                string[]      includePaths = resolvedConflict.Split(',');
                List <string> path         = new List <string>();
                foreach (string includePath in includePaths)
                {
                    string temp;
                    temp = includePath.NormalizeInclude();
                    path.Add(temp);
                }
                return(MergeConflict.PathToNode(path));
            }
            else
            {
                string        temp;
                List <string> path = new List <string>();
                temp = resolvedConflict.NormalizeInclude();
                path.Add(temp);
                return(MergeConflict.PathToNode(path));
            }
        }
示例#4
0
        /// <summary>
        /// Execute all synthesized codes on the merge conflict
        /// </summary>
        /// <param name="input">Merge conflict</param>
        /// <param name="programList">List of synthesized programs</param>
        /// <param name="type">1=include, 2= macro related conflicts</param>
        /// <returns>List of all matched resolutions</returns>
        internal static List <IReadOnlyList <Node> > LoadAllSynthesizedCode(MergeConflict input, List <Program> programList, int type)
        {
            List <IReadOnlyList <Node> > outputQueue = new List <IReadOnlyList <Node> >();

            if (type == 1)
            {
                outputQueue.Add(programList[0].Run(input));
                outputQueue.Add(programList[1].Run(input));
                outputQueue.Add(programList[2].Run(input));
                outputQueue.Add(programList[3].Run(input));
                if (Semantics.NodeValue(input.Upstream[0], "path") != "")
                {
                    outputQueue.Add(programList[4].Run(input));
                }
                outputQueue.Add(programList[5].Run(input));
                outputQueue.Add(programList[6].Run(input));
                outputQueue.Add(programList[7].Run(input));
                outputQueue.Add(programList[8].Run(input));
            }
            else
            {
                outputQueue.Add(programList[9].Run(input));
                outputQueue.Add(programList[10].Run(input));
            }
            return(outputQueue);
        }
示例#5
0
文件: Sync.cs 项目: aata/szotar
        protected void OnMergeConflict(WordList set, MergeConflict conflict)
        {
            var h = MergeConflict;

            if (h != null)
            {
                SynchronizationContext.Current.Post(x => h(this, set, conflict), null);
            }
        }
示例#6
0
        /// <summary>
        /// Load the output after running all the testcases. If there is no pattern returned then the default behavior is concatenating the main and the
        /// for branch. Since we only concentrate on the structural conflicts, the order of the conflicts do not matter. So, we validate the solution
        /// with the resolved conflict by main followed by fork and fork followed by main.
        /// </summary>
        /// <param name="input">Merge conflict</param>
        /// <param name="programList">List of synthesized programs</param>
        /// <param name="testcasePath">Location of the testcase</param>
        /// <param name="number">Test case index</param>
        /// <returns>True if matches with the resolution provided by user, false otherwise</returns>
        public static bool ValidOutput(MergeConflict input, List <Program> programList, string testcasePath, string number)
        {
            string resolvedFilename                  = testcasePath + number + "_Resolved.txt";
            string conflict                          = testcasePath + number + "_Conflict.txt";
            int    typeOfConflict                    = conflictType(conflict);
            IReadOnlyList <Node>         output      = readResolvedConflicts(resolvedFilename, typeOfConflict);
            List <bool>                  checkOutput = new List <bool>();
            List <IReadOnlyList <Node> > outputQueue = LoadAllSynthesizedCode(input, programList, typeOfConflict);
            bool flagStart = false;
            bool flagValid = false;

            foreach (IReadOnlyList <Node> n in outputQueue)
            {
                if (n != null)
                {
                    if (n.Count > 0)
                    {
                        flagStart = true;
                        if (Equal(n, output))
                        {
                            flagValid = true;
                        }
                    }
                }
            }
            if (flagValid)
            {
                checkOutput.Add(true);
            }
            else if (flagStart == false)
            {
                if (Equal(Semantics.Concat(input.Downstream, input.Upstream), output) == true || Equal(Semantics.Concat(input.Upstream, input.Downstream), output) == true)
                {
                    checkOutput.Add(true);
                }
                else if (Semantics.NodeValue(input.Upstream[0], "path") == "")
                {
                    if (Equal(input.Downstream, output) == true)
                    {
                        checkOutput.Add(true);
                    }
                    else
                    {
                        checkOutput.Add(false);
                    }
                }
                else
                {
                    checkOutput.Add(false);
                }
            }
            else
            {
                checkOutput.Add(false);
            }
            return(checkOutput[0]);
        }
示例#7
0
        /// <summary>
        /// Gets the name of the entity that did cause the specified merge conflict.
        /// </summary>
        /// <param name="mergeConflict"> The merge conflict. </param>
        /// <returns> The get entity name. </returns>
        private static string GetEntityName(MergeConflict mergeConflict)
        {
            var element = mergeConflict.SourceElement ?? mergeConflict.TargetElement ?? mergeConflict.BaselineElement;
            var type    = element.GetType().Name;

            switch (type)
            {
            case "StdContact":
                return(((StdContact)element).GetFullName());

            default:
                return(element.ToSortSimple());
            }
        }
示例#8
0
 private PathStatus OnMergeConflict(string path, PathStatus status)
 {
     if (Options.PerPathNotificationCallback != null)
     {
         if (status == null)
         {
             status = new PathStatus(Repository, path);
         }
         status.IndexPathStatus = IndexPathStatus.MergeConflict;
     }
     MergeConflict.Add(path);
     AnyDifferences = true;
     return(status);
 }
示例#9
0
        public void MacroTest()
        {
            List <bool>    checkOutput   = new List <bool>();
            List <Program> programList   = TestUtils.LoadProgram();
            string         testcasePath  = @"..\..\..\..\..\Dataset\MacroSuite";
            string         filePath      = @"..\..\..\..\..\Dataset\Files\";
            List <string>  countTestCase = TestUtils.TestCaseLoad(testcasePath);

            foreach (string number in countTestCase)
            {
                MergeConflict input = TestUtils.LoadTestInput(testcasePath, number, filePath);
                Assert.IsTrue(TestUtils.ValidOutput(input, programList, testcasePath, number));
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            // Two examples of conflicts and resolutions
            string conflict1   = @"<<<<<<< HEAD
#include ""base/command_line.h""
#include ""base/logging.h""
=======
#include ""base/check_op.h""
>>>>>>>";
            string resolution1 = @"#include ""base/command_line.h""
#include ""base/check_op.h""";

            string conflict2   = @"<<<<<<< HEAD
#include ""base/logging.h""
#include ""base/scoped_native_library.h""
=======
#include ""base/notreached.h""
>>>>>>>";
            string resolution2 = @"#include ""base/scoped_native_library.h""
#include ""base/notreached.h""";

            MergeConflict            input1   = new MergeConflict(conflict1);
            MergeConflict            input2   = new MergeConflict(conflict2);
            List <ResolutionExample> examples = new List <ResolutionExample>
            {
                new ResolutionExample(input1, resolution1),
                new ResolutionExample(input2, resolution2)
            };

            // Learn with two examples
            Program program = Learner.Instance.Learn(examples);

            // Execute the program on new, unseen input to get the resolution
            string        newConflict = @"<<<<<<< HEAD
#include ""ui/base/anonymous_ui_base_features.h""
#include ""base/logging.h""
=======
#include ""ui/base/cursor/mojom/cursor_type.mojom-blink.h""
>>>>>>>";
            MergeConflict newInput    = new MergeConflict(newConflict);
            string        resolution  = program.RunString(newInput);

            Console.WriteLine(resolution);
        }
示例#11
0
文件: Sync.cs 项目: dbremner/szotar
		protected void OnMergeConflict(WordList set, MergeConflict conflict) {
			var h = MergeConflict;
			if (h != null)
				SynchronizationContext.Current.Post(x => h(this, set, conflict), null);
		}
示例#12
0
        /// <summary>
        /// Run the diff operation. Until this is called, all lists will be empty
        /// </summary>
        /// <returns>true if anything is different between index, tree, and workdir</returns>
        private void UpdateDirectory(IEnumerable <string> paths, bool recursive)
        {
            RevWalk  rw     = new RevWalk(Repository);
            ObjectId id     = Repository.Resolve(Constants.HEAD);
            var      commit = id != null?rw.ParseCommit(id) : null;

            TreeWalk treeWalk = new TreeWalk(Repository);

            treeWalk.Reset();
            treeWalk.Recursive = false;

            if (commit != null)
            {
                treeWalk.AddTree(commit.Tree);
            }
            else
            {
                treeWalk.AddTree(new EmptyTreeIterator());
            }

            DirCache dc = Repository.ReadDirCache();

            treeWalk.AddTree(new DirCacheIterator(dc));

            FileTreeIterator workTree = new FileTreeIterator(Repository.WorkTree, Repository.FileSystem, WorkingTreeOptions.KEY.Parse(Repository.GetConfig()));

            treeWalk.AddTree(workTree);

            List <TreeFilter> filters = new List <TreeFilter> ();

            filters.Add(new SkipWorkTreeFilter(1));

            var pathFilters = paths.Where(p => p != ".").Select(p => PathFilter.Create(p)).ToArray();

            if (pathFilters.Length > 1)
            {
                filters.Add(OrTreeFilter.Create(pathFilters));                   // Use an OR to join all path filters
            }
            else if (pathFilters.Length == 1)
            {
                filters.Add(pathFilters[0]);
            }

            if (filters.Count > 1)
            {
                treeWalk.Filter = AndTreeFilter.Create(filters);
            }
            else
            {
                treeWalk.Filter = filters[0];
            }

            while (treeWalk.Next())
            {
                AbstractTreeIterator treeIterator        = treeWalk.GetTree <AbstractTreeIterator>(0);
                DirCacheIterator     dirCacheIterator    = treeWalk.GetTree <DirCacheIterator>(1);
                WorkingTreeIterator  workingTreeIterator = treeWalk.GetTree <WorkingTreeIterator>(2);
                NGit.FileMode        fileModeTree        = treeWalk.GetFileMode(0);

                if (treeWalk.IsSubtree)
                {
                    treeWalk.EnterSubtree();
                    continue;
                }

                int stage = dirCacheIterator != null?dirCacheIterator.GetDirCacheEntry().Stage : 0;

                if (stage > 1)
                {
                    continue;
                }
                else if (stage == 1)
                {
                    MergeConflict.Add(dirCacheIterator.EntryPathString);
                    changesExist = true;
                    continue;
                }

                if (treeIterator != null)
                {
                    if (dirCacheIterator != null)
                    {
                        if (!treeIterator.EntryObjectId.Equals(dirCacheIterator.EntryObjectId))
                        {
                            // in repo, in index, content diff => changed
                            Modified.Add(dirCacheIterator.EntryPathString);
                            changesExist = true;
                        }
                    }
                    else
                    {
                        // in repo, not in index => removed
                        if (!fileModeTree.Equals(NGit.FileMode.TYPE_TREE))
                        {
                            Removed.Add(treeIterator.EntryPathString);
                            changesExist = true;
                        }
                    }
                }
                else
                {
                    if (dirCacheIterator != null)
                    {
                        // not in repo, in index => added
                        Added.Add(dirCacheIterator.EntryPathString);
                        changesExist = true;
                    }
                    else
                    {
                        // not in repo, not in index => untracked
                        if (workingTreeIterator != null && !workingTreeIterator.IsEntryIgnored())
                        {
                            Untracked.Add(workingTreeIterator.EntryPathString);
                            changesExist = true;
                        }
                    }
                }
                if (dirCacheIterator != null)
                {
                    if (workingTreeIterator == null)
                    {
                        // in index, not in workdir => missing
                        Missing.Add(dirCacheIterator.EntryPathString);
                        changesExist = true;
                    }
                    else
                    {
                        // Workaround to file time resolution issues
                        long itime = dirCacheIterator.GetDirCacheEntry().LastModified;
                        long ftime = workingTreeIterator.GetEntryLastModified();
                        if (itime / 1000 != ftime / 1000)
                        {
                            if (!dirCacheIterator.IdEqual(workingTreeIterator))
                            {
                                // in index, in workdir, content differs => modified
                                Modified.Add(dirCacheIterator.EntryPathString);
                                changesExist = true;
                            }
                        }
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// Run the diff operation. Until this is called, all lists will be empty
        /// </summary>
        /// <returns>true if anything is different between index, tree, and workdir</returns>
        public bool Diff()
        {
            DirectoryInfo root    = _index.Repository.WorkingDirectory;
            var           visitor = new AbstractIndexTreeVisitor
            {
                VisitEntry = delegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file)
                {
                    if (treeEntry == null)
                    {
                        Added.Add(indexEntry.Name);
                        _anyChanges = true;
                    }
                    else if (indexEntry == null)
                    {
                        if (!(treeEntry is Tree))
                        {
                            Removed.Add(treeEntry.FullName);
                        }
                        _anyChanges = true;
                    }
                    else
                    {
                        if (!treeEntry.Id.Equals(indexEntry.ObjectId))
                        {
                            Changed.Add(indexEntry.Name);
                            _anyChanges = true;
                        }
                    }

                    if (indexEntry != null)
                    {
                        if (!file.Exists)
                        {
                            Missing.Add(indexEntry.Name);
                            _anyChanges = true;
                        }
                        else
                        {
                            if (indexEntry.IsModified(root, true))
                            {
                                Modified.Add(indexEntry.Name);
                                _anyChanges = true;
                            }
                        }
                    }

                    if (indexEntry != null)
                    {
                        if (indexEntry.Stage != 0)
                        {
                            MergeConflict.Add(indexEntry.Name);
                            _anyChanges = true;
                        }
                    }
                }
            };

            new IndexTreeWalker(_index, _tree, root, visitor).Walk();

            CheckUntrackedDirectory(root.FullName, string.Empty);

            return(_anyChanges);
        }