In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
What are the knowledge points of this article "what are the methods provided by Rugged::Repository?" most people do not understand, so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the methods provided by Rugged::Repository?"
1. Concept
A.rugged is a libgit2 access library based on ruby language, which provides good speed and portability and has the beautiful features of Ruby language.
B.libgit2 is a pure c implementation of git core methods, which is designed with both speed and portability.
two。 Installation
Premise: first of all, according to the ruby environment and the gem ruby package manager (not described here, but google), the environment ubuntu
The installation commands are as follows:
$> gem install rugged
Possible problem: package dependency problem, can also be based on error google
3. Document
$> gem server
You can open the web server built into gem, browse all installed software and their documentation, and open http://localhost:8808
Internal modules and common classes of 4.rugged library
There is mainly a module Rugged with Rugged::Repository,Rugged::Commit,Rugged::Branch in it.
Rugged::BranchCollections,Rugged::Object,Rugged:Tag,Rugged::Config,Rugged::Remote
Rugged::Index,Rugged::SettingsRugged::Reference,Rugged::Patch,Rugged::Tree,Rugged::Diff
Rugged::Error,Rugged::Credentials and other related modules and classes will be introduced one by one later.
5. Give it a try.
Require 'rugged'# Import rugged module repo = Rugged::Repository.new (' / home/lry/workspace/ruby_test/git_test/.git') # Open git repository from the git path given by the parameter Return the Rugged::Repository object puts Rugged::Repository.discover ("/ home/lry/workspace/ruby_test/git_test/.git") # = > "/ home/lry/workspace/ruby_test/git_test/.git" puts repo.exists? ('e6a40e934434e11d1e8dad08cb95a49e9d5b2aec') # to determine whether the object represented by the given sha1 oid exists in repository. Sha1 can view the submitted file in git status by viewing # = > true puts repo.bare?# = > falseputs repo.empty?# due to the existence of my working directory So empty # = > falseputs repo.head_detached?# = > falseputs repo.path# = > "/ home/lry/workspace/ruby_test/git_test/.git/" puts repo.workdir# = > "/ home/lry/workspace/ruby_test/git_test/" # The HEAD of the repository.puts ref = repo.head# = > # puts ref.name# = > "refs/heads/master" ref.target# = > # object = repo.read ('e6a40e934434e11d1e8dad08cb95a49e9d5b2aec') # = > # puts object.len # = > 171puts object.data# = > "tree 203809dc435dd4e78d203cbf766a17581d77b2fa author # committer # add readme" puts object.type# = >: commit
Class structure Organization of 6.Rugged
First of all, let's explain that git, git stores each file, rather than recording the differences between versions like svn.
Repository contains a lot of Reference,Reference which can be Reference or Branch or Tag or AnnotationTag,Reference pointing to a target,Reference type type is: symbolic or: direct, if type is: direct type, then
Target is Commit, otherwise it is another Reference.
Reference such as refs/heads/master, refs/remotes/origin/master, refs/heads/zql/master, refs/tags/v1.0
Branch such as refs/heads/master, refs/heads/zql/master,refs/remotes/origin/master
Tag such as refs/tags/v1.0
AnnotationTag refers to tag with message.
Commit is a submission, and a submission represents a version, and each Commit contains all the files for that version, as shown in the following figure
A) Version 1 includes the file A _ mae B _ r C
B) modified the file A _ Magi C; evolved into Version 2, including the file A _ 1m B ~ C _ 1
C) modified file C1; evolved into Version 3, including files A1, B, C2
D) modified the file A1 Magi B; evolved into Version 4, including the file A 2 Magi B 1 rec 2
E) modified the file B1MageC2; evolved into Version 5, including files A2MagneB2, C3.
The above represents the file transition history of git. Further, Commit points to a Tree,Tree project with Trees and Blobs as well as Tree pointed to by Commits,Commit as the root tree, Tree represents a directory, of course, the root tree represents the top-level directory, and the path is ""; Blob represents files; and Commit represents submodules. You can also have subdirectories and files and submodules under each directory, as shown in the following figure:
The parents of each Commit points to its parent submission, that is, its previous submission (of course, there can be multiple, such as merge), such as Version 4 when the parent of Version 5 above commits. The following figure shows how Commit is organized:
It is worth noting that the file (directory) information and content are stored separately, the file information contains the oid of the file, through the oid and then to the warehouse through idx to pack to find the file content.
7. Detailed explanation of related modules and classes
1)。 Of course, the most important class is Rugged::Repository, which we can use to manipulate git repository on disk.
a. Initialization method
Bare (path [, alternates]) → repository
Open a bare git repository with the path (including .git) of the .git parameter path. Returns the object that Rugged::Repository represents the repository
Init_at (path, is_bare = false) → repository example: Rugged::Repository.init_at ('~ / repository',: bare) # = > #
Initialize repository if it does not exist, otherwise reinitialize it. The parameter path is the path above .git (excluding .git), and the parameter is_bare indicates whether to initialize repository with bare. Default is false. Returns the object that Rugged::Repository represents the repository
New (path, options = {}) → repository example: Rugged::Repository.new ('~ / test/.git') # = > # Rugged::Repository.new (path,: alternates = > ['. / other/repo/.git/objects'])
Open a repository with the parameter path to the path of .git or the path above it. Options indicates the optional parameter, followed by the path to the subdirectory of .git. Returns the object that Rugged::Repository represents the repository. If you need to create a repository, use Rugged::init_at instead.
Clone_at (url, local_path [, options]) → repository example: Repository.clone_at ("https://github.com/libgit2/rugged.git",". / some/dir ", {transfer_progress: lambda {| total_objects, indexed_objects, received_objects, local_objects, total_deltas, indexed_deltas, received_bytes | #...}})
Get a copy of git from the remote address. Url is the address of the project repository and local_path is the directory of the local copy. Returns the object that Rugged::Repository represents the repository.
Options has the following Hash options:
: bare
Iftrue, the clone will be created as a bare repository. Defaults tofalse.
: checkout_branch
The name of a branch to checkout. Defaults to the remote'sHEAD.
: remote
The name to give to the "origin" remote. Defaults to "origin".
: ignore_cert_errors
If set totrue, errors while validating the remote's host certificate will be ignored.
: credentials
The credentials to use for the clone operation. Can be either an instance of one of the Rugged::Credentials types, or a proc returning one of the former. The proc will be called with theurl, theusernamefrom theurl (if applicable) and a list of applicable credential types.
: progress
A callback that will be executed with the textual progress received from the remote. This is the text send over the progress side-band (ie. The "counting objects" output).
: transfer_progress
A callback that will be executed to report clone progress information. It will be passed the amount oftotal_objects,indexed_objects,received_objects,local_objects,total_deltas,indexed_deltas, andreceived_bytes.
: update_tips
A callback that will be executed each time a reference was updated locally. It will be passed therefname,old_oidandnew_oid.
b. Basic method
Discover (path = nil, across_fs = true) → repository
The path passed by path searches the .git folder up, then opens and generates a Rugged::Repository object, starting with the current path if path is nil
Hash_data (str, type) → oid Repository.hash_data ('hello world',: commit) # = > "de5ba987198bcf2518885f0fc1350e5172cded78" Repository.hash_data (' hello_world',: tag) # = > "9d09060c850defbc7711d08b57def0d14e742f4e"
Returns the hash value of str. Hash str as raw data plus the corresponding header of type. Returns the hash value string of the result
Hash_file (path, type) → oid
Returns the hash value of the file pointed to by path. A string that returns the SHA1 value
Create_branch (name, sha_or_ref = "HEAD")
Create a branch in the repository, and name specifies the branch name, sha_ora_ref target branch, which can be oid,reference name or Rugged::Object instance. Returns the Rugged::Branch object
Branches ()
Returns the branch in the current repository, and returns the collection of BranchCollection objects for Rugged::Branch
Checkout (target, options = {})
Switch to branch, reference or commit. Specified by target.
Checkout_head ([options]) → nil
Switch to HEAD
Ref (ref_name) example: repo.ref 'refs/heads/master' # = > #
Find the Rugged::Reference object defined by ref_name
Ref_names (glob = nil) references () # gets all the Referece,ReferenceCollection representations in the warehouse refs (glob = nil) head → ref
Get the Rugged::Reference object pointing to repository Head
Head = str
Set the Head of repository
Index → idx index = idx
Gets or sets the default index,idx of repository to the Rugged::Index object
Namespace → str namespace = new_namespace
Sets or sets the active namespace for repository
Path → path
Get the complete, standard .git path
Workdir → path or nil workdir = path
Gets or sets the working directory of repository
Config → cfg config = cfg
Gets and sets the configuration .cfg as a Rugged::Config object
Lookup (oid)
Find a SHA1 and return an object that inherits one of the four classes of Rugged::Object
Exists? (oid) → true or false
Whether a given SHA1 OID (represented as a 40-character string) exists in repository
Include? (oid) → true or false repo.include? ("d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f") # = > true
Whether a given SHA1 OID (represented as a 40-character string) exists in repository
Tags ()
Get all the tag of repository. Returns the collection Rugged::TagCollection object of Rugged::Tag
Remotes ()
Get all the remotes of repository. Returns the collection Rugged::RemoteCollection object of Rugged::Remote
Push (remote_or_url, * args)
Push refspecs to remote_or_url. Return refspecs as the key value. If the success value is nil, the failure is an error message.
Last_commit ()
Get the last commit and return the Rugged::Commit object
Read (oid) → str
Read the original data of the object identified by the oid object
Read_header (oid) → hash
Read the Head information of repository. Returns a Hash object with the following possible key-value pairs
: type = > A Symbol denoting the object's type. Possible values: tree,:blob,:commit or: tag.
: len = > the length of the above objects
Rev_parse (spec)
Find the object through the revision string. Returns an object that inherits one of the four classes of Rugged::Object
Rev_parse_oid (spec)
Find oid. Revision through the string. Returns the oid that matches revision
Write (buffer, type) → oid
Write the data in buffer to repository's object database. Repository's object database as the given type type.
Available values for type are: tag,:commit,:treeor:blob.
Returns the oid of the newly created object
Blob_at (revision, path)
Gets the blob of the revision of the specified path path.
Revision-The String SHA1.
Path-The String file path.
Returns a string
Diff (left, right, opts = {}) diff_workdir (left, opts = {})
Specify two versions of diff
Merge_base (oid1, oid2,...) Merge_base (ref1, ref2,...) Merge_base (commit1, commit2,...)
Find the merged base
Merge_commits (our_commit, their_commit, options = {}) → index
Merge operation. Our _ commitandtheir_commitcan either be Rugged::Commit objects, or OIDs resolving to the former. Returns the merged Rugged::Index object
Each_id {| id | block} each_id → Iterator
Performs a block iteration for each object ID found in repository, and the id is a 40-character string
Status {| file, status_data | block} status (path) → status_data example: repo.status {| file, status_data | puts "# {file} has status: # {status_data.inspect}"} repo.status ('src/diff.c') # = > [: index_new,: worktree_new]
Gets the status of the files in the working directory.
c. Manipulate object database
Read (oid) example: object = repo.read ('a0ae5566e3c8a3bddffab21022056f0b5e03ef07') # = >
Reading Rugged::OdbObject objects through oid
Rugged::OdbObject.data () Rugged::OdbObject.len () Rugged::OdbObject.type () Rugged::OdbObject.oid () example: object.len# = > 237 object.data # = > "tree 76f23f186076fc291742816721ea8c3e95567241\ nparent 8e3c5c52b8f29da0adc7e8be8a037cbeaea6de6b\ nauthor Vicent Mart\ 303\ 255 1333859005 + 0200\ ncommitter Vicent Mart\ 303\ 255 1333859005 + 0200\ n\ nAdd `Repository#blob_ at`\ n" object.type# = >: commit object.oid#= > "d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f" the above is about " What are the methods provided by Rugged::Repository? what is the content of this article I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.