Example #1
0
        public void test021_createTreeTag()
        {
            ObjectId emptyId         = new ObjectWriter(db).WriteBlob(new byte[0]);
            var      almostEmptyTree = new Core.Tree(db);

            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var t = new Core.Tag(db)
            {
                Id      = almostEmptyTreeId,
                TagType = "tree",
                TagName = "test021",
                Author  = new PersonIdent(author, 1154236443000L, -4 * 60),
                Message = "test021 tagged\n"
            };

            t.Save();
            Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name);

            Core.Tag MapTag = db.MapTag("test021");
            Assert.AreEqual("tree", MapTag.TagType);
            Assert.AreEqual("test021 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name);
        }
Example #2
0
        public void test025_packedRefs()
        {
            test020_createBlobTag();
            test021_createTreeTag();
            test022_createCommitTag();

            new FileInfo(db.Directory.FullName + "/refs/tags/test020").Delete();
            if (new FileInfo(db.Directory.FullName + "/refs/tags/test020").Exists)
            {
                throw new IOException("Cannot delete unpacked tag");
            }
            new FileInfo(db.Directory.FullName + "/refs/tags/test021").Delete();
            if (new FileInfo(db.Directory.FullName + "/refs/tags/test021").Exists)
            {
                throw new IOException("Cannot delete unpacked tag");
            }
            new FileInfo(db.Directory.FullName + "/refs/tags/test022").Delete();
            if (new FileInfo(db.Directory.FullName + "/refs/tags/test022").Exists)
            {
                throw new IOException("Cannot delete unpacked tag");
            }

            // We cannot Resolve it now, since we have no ref
            Core.Tag mapTag20missing = db.MapTag("test020");
            Assert.IsNull(mapTag20missing);

            // Construct packed refs file
            var fs = new FileStream(db.Directory.FullName + "/packed-refs", System.IO.FileMode.Create);
            var w  = new StreamWriter(fs);

            w.WriteLine("# packed-refs with: peeled");
            w.WriteLine("6759556b09fbb4fd8ae5e315134481cc25d46954 refs/tags/test020");
            w.WriteLine("^e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
            w.WriteLine("b0517bc8dbe2096b419d42424cd7030733f4abe5 refs/tags/test021");
            w.WriteLine("^417c01c8795a35b8e835113a85a5c0c1c77f67fb");
            w.WriteLine("0ce2ebdb36076ef0b38adbe077a07d43b43e3807 refs/tags/test022");
            w.WriteLine("^b5d3b45a96b340441f5abb9080411705c51cc86c");
            w.Close();

            Core.Tag mapTag20 = db.MapTag("test020");
            Assert.IsNotNull(mapTag20, "have tag test020");
            Assert.AreEqual("blob", mapTag20.TagType);
            Assert.AreEqual("test020 tagged\n", mapTag20.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag20.Author);
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.Id.Name);

            Core.Tag mapTag21 = db.MapTag("test021");
            Assert.AreEqual("tree", mapTag21.TagType);
            Assert.AreEqual("test021 tagged\n", mapTag21.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag21.Author);
            Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.Id.Name);

            Core.Tag mapTag22 = db.MapTag("test022");
            Assert.AreEqual("commit", mapTag22.TagType);
            Assert.AreEqual("test022 tagged\n", mapTag22.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag22.Author);
            Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.Id.Name);
        }
        /// <summary>
        /// Patch the similarity matrix so that tags which are not aligned can't be associated
        /// by the ED
        /// </summary>
        private void PatchSimilarityMatrix(SimilarityMatrix sim,
                                           IList <Core.Tokenization.Token> srcTokens,
                                           IList <Core.Tokenization.Token> trgTokens,
                                           TagAssociations tagAlignment)
        {
            if (tagAlignment == null || tagAlignment.Count == 0)
            {
                return;
            }

            for (int s = 0; s < srcTokens.Count; ++s)
            {
                if (!(srcTokens[s] is Core.Tokenization.TagToken))
                {
                    // not a tag
                    continue;
                }

                Core.Tag st = ((Core.Tokenization.TagToken)srcTokens[s]).Tag;
                if (!(st.Type == TagType.Start || st.Type == TagType.End))
                {
                    // not a paired tag
                    continue;
                }

                for (int t = 0; t < trgTokens.Count; ++t)
                {
                    if (sim.IsAssigned(s, t) && sim[s, t] < 0.0d)
                    {
                        // invalid assignment anyway, no need to check further
                        continue;
                    }

                    if (!(trgTokens[t] is Core.Tokenization.TagToken))
                    {
                        // should't really be the case as then sim[s, t] < 0
                        System.Diagnostics.Debug.Assert(false, "Shouldn't be");
                        continue;
                    }

                    Core.Tag tt = ((Core.Tokenization.TagToken)trgTokens[t]).Tag;
                    if (!(tt.Type == TagType.Start || tt.Type == TagType.End))
                    {
                        // should't really be the case as then sim[s, t] < 0
                        System.Diagnostics.Debug.Assert(false, "Shouldn't be");
                        continue;
                    }

                    if (!tagAlignment.AreAssociated(s, t))
                    {
                        sim[s, t] = -1.0d;
                    }
                }
            }
        }
Example #4
0
        protected RevTag Tag(string name, RevObject dst)
        {
            var t = new Core.Tag(db)
            {
                TagType = Constants.typeString(dst.Type),
                Id      = dst.ToObjectId(),
                TagName = name,
                Tagger  = new PersonIdent(committer, (nowTick).MillisToDateTime()),
                Message = string.Empty
            };

            return((RevTag)rw.lookupAny(_ow.WriteTag(t), Constants.OBJ_TAG));
        }
Example #5
0
        public void test020b_createBlobPlainTag()
        {
            test020_createBlobTag();
            var t = new Core.Tag(db)
            {
                TagName = "test020b",
                Id      = ObjectId.FromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
            };

            t.Save();

            Core.Tag MapTag = db.MapTag("test020b");
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", MapTag.Id.Name);

            // We do not repeat the plain tag test for other object types
        }
Example #6
0
        public void test020_createBlobTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var      t       = new Core.Tag(db)
            {
                Id      = emptyId,
                TagType = "blob",
                TagName = "test020",
                Author  = new PersonIdent(author, 1154236443000L, -4 * 60),
                Message = "test020 tagged\n"
            };

            t.Save();
            Assert.AreEqual("6759556b09fbb4fd8ae5e315134481cc25d46954", t.TagId.Name);

            Core.Tag MapTag = db.MapTag("test020");
            Assert.AreEqual("blob", MapTag.TagType);
            Assert.AreEqual("test020 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", MapTag.Id.Name);
        }
Example #7
0
        public void test022_createCommitTag()
        {
            ObjectId emptyId         = new ObjectWriter(db).WriteBlob(new byte[0]);
            var      almostEmptyTree = new Core.Tree(db);

            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var almostEmptyCommit = new Core.Commit(db)
            {
                Author    = new PersonIdent(author, 1154236443000L, -2 * 60),
                Committer = new PersonIdent(author, 1154236443000L, -2 * 60),
                Message   = "test022\n",
                TreeId    = almostEmptyTreeId
            };

            ObjectId almostEmptyCommitId = new ObjectWriter(db).WriteCommit(almostEmptyCommit);

            var t = new Core.Tag(db)
            {
                Id      = almostEmptyCommitId,
                TagType = "commit",
                TagName = "test022",
                Author  = new PersonIdent(author, 1154236443000L, -4 * 60),
                Message = "test022 tagged\n"
            };

            t.Save();
            Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.TagId.Name);

            Core.Tag mapTag = db.MapTag("test022");
            Assert.AreEqual("commit", mapTag.TagType);
            Assert.AreEqual("test022 tagged\n", mapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.Author);
            Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.Id.Name);
        }
Example #8
0
        public void test022_createCommitTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Core.Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var almostEmptyCommit = new Core.Commit(db)
                                        {
                                            Author = new PersonIdent(author, 1154236443000L, -2*60),
                                            Committer = new PersonIdent(author, 1154236443000L, -2*60),
                                            Message = "test022\n",
                                            TreeId = almostEmptyTreeId
                                        };

            ObjectId almostEmptyCommitId = new ObjectWriter(db).WriteCommit(almostEmptyCommit);

            var t = new Core.Tag(db)
                        {
                            Id = almostEmptyCommitId,
                            TagType = "commit",
                            TagName = "test022",
                            Author = new PersonIdent(author, 1154236443000L, -4*60),
                            Message = "test022 tagged\n"
                        };

            t.Save();
            Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.TagId.Name);

            Core.Tag mapTag = db.MapTag("test022");
            Assert.AreEqual("commit", mapTag.TagType);
            Assert.AreEqual("test022 tagged\n", mapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.Author);
            Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.Id.Name);
        }
Example #9
0
        public void test021_createTreeTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Core.Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var t = new Core.Tag(db)
                        {
                            Id = almostEmptyTreeId,
                            TagType = "tree",
                            TagName = "test021",
                            Author = new PersonIdent(author, 1154236443000L, -4*60),
                            Message = "test021 tagged\n"
                        };

            t.Save();
            Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name);

            Core.Tag MapTag = db.MapTag("test021");
            Assert.AreEqual("tree", MapTag.TagType);
            Assert.AreEqual("test021 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name);
        }
Example #10
0
        public void test020_createBlobTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var t = new Core.Tag(db)
                        {
                            Id = emptyId,
                            TagType = "blob",
                            TagName = "test020",
                            Author = new PersonIdent(author, 1154236443000L, -4*60),
                            Message = "test020 tagged\n"
                        };
            t.Save();
            Assert.AreEqual("6759556b09fbb4fd8ae5e315134481cc25d46954", t.TagId.Name);

            Core.Tag MapTag = db.MapTag("test020");
            Assert.AreEqual("blob", MapTag.TagType);
            Assert.AreEqual("test020 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", MapTag.Id.Name);
        }
Example #11
0
        public void test020b_createBlobPlainTag()
        {
            test020_createBlobTag();
            var t = new Core.Tag(db)
                        {
                            TagName = "test020b",
                            Id = ObjectId.FromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")
                        };
            t.Save();

            Core.Tag MapTag = db.MapTag("test020b");
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", MapTag.Id.Name);

            // We do not repeat the plain tag test for other object types
        }
Example #12
0
        public string Upload(IPhoto photo, IFilter filter, bool is_public, bool is_family, bool is_friend)
        {
            if (token == null)
            {
                throw new Exception("Must Login First");
            }
            // FIXME flickr needs rotation
            string error_verbose;

            using (FilterRequest request = new FilterRequest(photo.DefaultVersion.Uri)) {
                try {
                    string tags = null;

                    filter.Convert(request);
                    string path = request.Current.LocalPath;

                    if (ExportTags && photo.Tags != null)
                    {
                        var         taglist  = new StringBuilder();
                        Core.Tag [] t        = photo.Tags;
                        Core.Tag    tag_iter = null;

                        for (int i = 0; i < t.Length; i++)
                        {
                            if (i > 0)
                            {
                                taglist.Append(",");
                            }

                            taglist.Append(string.Format("\"{0}\"", t [i].Name));

                            // Go through the tag parents
                            if (ExportTagHierarchy)
                            {
                                tag_iter = t [i].Category;
                                while (tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null)
                                {
                                    // Skip top level tags because they have no meaning in a linear tag database
                                    if (ExportIgnoreTopLevel && tag_iter.Category == App.Instance.Database.Tags.RootCategory)
                                    {
                                        break;
                                    }

                                    // FIXME Look if the tag is already there!
                                    taglist.Append(",");
                                    taglist.Append(string.Format("\"{0}\"", tag_iter.Name));
                                    tag_iter = tag_iter.Category;
                                }
                            }
                        }

                        tags = taglist.ToString();
                    }
                    try {
                        string photoid =
                            flickr.UploadPicture(path, photo.Name, photo.Description, tags, is_public, is_family, is_friend);
                        return(photoid);
                    } catch (FlickrException ex) {
                        Log.Error("Problems uploading picture: " + ex.Message);
                        error_verbose = ex.ToString();
                    }
                } catch (Exception e) {
                    // FIXME we need to distinguish between file IO errors and xml errors here
                    throw new Exception("Error while uploading", e);
                }
            }

            throw new Exception(error_verbose);
        }