Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the Rugged::Commit class

Shulou Source: shulou.com Published: 2022-05-31 12:25:03 10月02日 Update

This article mainly introduces the relevant knowledge of how to use the Rugged::Commit class, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use the Rugged::Commit class. Let's take a look at it.

1. Traverse the Commits of the warehouse

Rugged::Walker is used to traverse the commits collection of the repository.

Walker = Rugged::Walker.new (repo) # cwalker.sorting (Rugged::SORT_TOPO | Rugged::SORT_REVERSE) # traversal mode (reverse by topology You can also use chronological order) walker.push (hex_sha_interesting) # the oid (sha) value of the commit you are interested in, starting from this sha to traverse the walker.hide (hex_sha_uninteresting) # sha (thus including the sha in front of it) walker.each {| c | puts c.inspect} # traverse the output walker.reset

two。 Create Commit

Author = {: email= > "zouqilin@csu.edu.cn",: time= > Time.now,: name= > "zouqilin"} # Code author committer = {: email= > "zouqilin@csu.edu.cn",: time= > Time.now,: name= > "zouqilin"} # submitter Rugged::Commit.create (r,: author = > author,: message = > "Hello world\ n\ n", # submission Information: committer = > author,: parents = > ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"], # parent submission: tree = > some_tree # Root tree built: update_ref = > "HEAD" # Branch name to be updated # = > "f148106ca58764adc93ad4e2d6b1d168422b9796" # return value Commit sa value created (oid)

3. Get the relevant properties and directories, files and submodule of Commit

Lastest_cmt = repo.head.target# get Commitroot_tree pointed to by HEAD = lastest_cmt.tree# get root tree entries = root_tree.entries# get root tree file and directory (including submodule) list entries.each {| e | puts e} # print # result: type= >: blob,: oid= > "99e7edb53db9355f10c6f2dfaa5a183f205d93bf",: filemode= > 100644,: name= > ".gitignore"} {: type= >: tree,: name= > "lib",: oid= > "e1253910439ea902cf49be8a9f02f3c08d89ac73" : filemode = > 040000} {: type = >: blob,: name = > "README.md",: oid = > "81b68f040b120c9627518213f7fc317d1ed18e1c" : filemode = > 0100644} raw_blob = repo.lookup ("81b68f040b120c9627518213f7fc317d1ed18e1c") # get raw_blob to get file size and content raw_blob.size # File size raw_blob.data# ascii encoded content raw_blob.text#utf-8 text raw_tree = repo.lookup ("e1253910439ea902cf49be8a9f02f3c08d89ac73") raw.entries# directory under entryraw.count# directory entries countraw.path ("lib/string.h") # get string.h 's entry about "Rugged" This article ends here on how to use the Commit class. Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use Rugged::Commit". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Content file directory knowledge repository size article code value author information interest branch attribute topology point submitter simple operation text article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS NVidia Shulou Information Huawei