public static Equals ( byte firstBuffer, int fi, byte secondBuffer, int si ) : bool | ||
firstBuffer | byte | /// the first buffer to compare against. Must have at least 20 /// bytes from position ai through the end of the buffer. /// |
fi | int | /// first offset within firstBuffer to begin testing. /// |
secondBuffer | byte | /// the second buffer to compare against. Must have at least 2 /// bytes from position bi through the end of the buffer. /// |
si | int | /// first offset within secondBuffer to begin testing. /// |
return | bool |
/// <summary> /// Update this index entry with stat and SHA-1 information if it looks /// like the file has been modified in the workdir. /// </summary> /// <param name="f">file in work dir</param> /// <returns> true if a change occurred </returns> /// <exception cref="IOException"></exception> public bool update(FileInfo f) { long lm = f.lastModified() * 1000000L; bool modified = Mtime != lm; Mtime = lm; if (_size != f.Length) { modified = true; } if (ConfigFileMode) { if (FileCanExecute(f) != FileMode.ExecutableFile.Equals(Mode)) { Mode = FileMode.ExecutableFile.Bits; modified = true; } } if (modified) { _size = (int)f.Length; var writer = new ObjectWriter(Repository); ObjectId newsha1 = ObjectId = writer.WriteBlob(f); modified = !newsha1.Equals(ObjectId); ObjectId = newsha1; } return(modified); }
/// <summary> /// Update this index entry with stat and SHA-1 information if it looks /// like the file has been modified in the workdir. /// </summary> /// <param name="f">file in work dir</param> /// <param name="newContent">the new content of the file </param> /// <returns> true if a change occurred </returns> /// <exception cref="IOException"></exception> public bool update(FileInfo f, byte[] newContent) //[henon] TODO: remove parameter f as it is useless { bool modified = false; _size = newContent.Length; var writer = new ObjectWriter(Repository); ObjectId newsha1 = ObjectId = writer.WriteBlob(newContent); if (!newsha1.Equals(ObjectId)) { modified = true; } ObjectId = newsha1; return(modified); }
/// <summary> /// Check if an entry's content is different from the cache, /// /// File status information is used and status is same we /// consider the file identical to the state in the working /// directory. Native git uses more stat fields than we /// have accessible in Java. /// </summary> /// <param name="wd"> working directory to compare content with </param> /// <param name="forceContentCheck"> /// True if the actual file content should be checked if modification time differs. /// </param> /// <returns> true if content is most likely different. </returns> public bool IsModified(DirectoryInfo wd, bool forceContentCheck) { if (isAssumedValid()) { return(false); } if (isUpdateNeeded()) { return(true); } FileInfo file = getFile(wd); if (!file.Exists) { return(true); } // JDK1.6 has file.canExecute // if (file.canExecute() != FileMode.EXECUTABLE_FILE.equals(mode)) // return true; int exebits = FileMode.ExecutableFile.Bits ^ FileMode.RegularFile.Bits; if (ConfigFileMode && FileMode.ExecutableFile.Equals(Mode)) { if (!FileCanExecute(file) && FileHasExecute()) { return(true); } } else { if (FileMode.RegularFile.Equals(Mode & ~exebits)) { if (!File.Exists(file.FullName) || ConfigFileMode && FileCanExecute(file) && FileHasExecute()) { return(true); } } else { if (FileMode.Symlink.Equals(Mode)) { return(true); } if (FileMode.Tree.Equals(Mode)) { if (!Directory.Exists(file.FullName)) { return(true); } } else { Console.WriteLine("Does not handle mode " + Mode + " (" + file + ")"); return(true); } } } if (file.Length != _size) { return(true); } // Git under windows only stores seconds so we round the timestamp // Java gives us if it looks like the timestamp in index is seconds // only. Otherwise we compare the timestamp at millisecond prevision. long javamtime = Mtime / 1000000L; long lastm = file.lastModified(); if (javamtime % 1000 == 0) { lastm = lastm - lastm % 1000; } if (lastm != javamtime) { if (!forceContentCheck) { return(true); } try { using (Stream @is = new FileStream(file.FullName, System.IO.FileMode.Open, FileAccess.Read)) { try { var objectWriter = new ObjectWriter(Repository); ObjectId newId = objectWriter.ComputeBlobSha1(file.Length, @is); bool ret = !newId.Equals(ObjectId); return(ret); } catch (IOException e) { e.printStackTrace(); } finally { try { @is.Close(); } catch (IOException e) { // can't happen, but if it does we ignore it e.printStackTrace(); } } } } catch (FileNotFoundException e) { // should not happen because we already checked this e.printStackTrace(); throw; } } return(false); }
private void ProcessEntry(TreeEntry h, TreeEntry m, GitIndex.Entry i) { ObjectId iId = (i == null ? null : i.ObjectId); ObjectId mId = (m == null ? null : m.Id); ObjectId hId = (h == null ? null : h.Id); string name = (i != null ? i.Name : (h != null ? h.FullName : m.FullName)); if (i == null) { // // I (index) H M Result // ------------------------------------------------------- // 0 nothing nothing nothing (does not happen) // 1 nothing nothing exists use M // 2 nothing exists nothing remove path from index // 3 nothing exists exists use M if (h == null) { _updated.Add(name, mId); } else if (m == null) { Removed.Add(name); } else { _updated.Add(name, mId); } } else if (h == null) { // // clean I==H I==M H M Result // ----------------------------------------------------- // 4 yes N/A N/A nothing nothing keep index // 5 no N/A N/A nothing nothing keep index // // 6 yes N/A yes nothing exists keep index // 7 no N/A yes nothing exists keep index // 8 yes N/A no nothing exists fail // 9 no N/A no nothing exists fail if (m == null || mId.Equals(iId)) { if (HasParentBlob(_merge, name)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { Removed.Add(name); } } } else { Conflicts.Add(name); } } else if (m == null) { // // 10 yes yes N/A exists nothing remove path from index // 11 no yes N/A exists nothing fail // 12 yes no N/A exists nothing fail // 13 no no N/A exists nothing fail // if (hId.Equals(iId)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { Removed.Add(name); } } else { Conflicts.Add(name); } } else { if (!hId.Equals(mId) && !hId.Equals(iId) && !mId.Equals(iId)) { Conflicts.Add(name); } else if (hId.Equals(iId) && !mId.Equals(iId)) { if (i.IsModified(_root, true)) { Conflicts.Add(name); } else { _updated.Add(name, mId); } } } }