1## git2r, R bindings to the libgit2 library. 2## Copyright (C) 2013-2018 The git2r contributors 3## 4## This program is free software; you can redistribute it and/or modify 5## it under the terms of the GNU General Public License, version 2, 6## as published by the Free Software Foundation. 7## 8## git2r is distributed in the hope that it will be useful, 9## but WITHOUT ANY WARRANTY; without even the implied warranty of 10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11## GNU General Public License for more details. 12## 13## You should have received a copy of the GNU General Public License along 14## with this program; if not, write to the Free Software Foundation, Inc., 15## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 17##' Get the SHA-1 of a git object 18##' 19##' Get the 40 character hexadecimal string of the SHA-1. 20##' @param object a git object to get the SHA-1 from. 21##' @return The 40 character hexadecimal string of the SHA-1. 22##' @export 23##' @examples \dontrun{ 24##' ## Create a directory in tempdir 25##' path <- tempfile(pattern="git2r-") 26##' dir.create(path) 27##' 28##' ## Initialize a repository 29##' repo <- init(path) 30##' config(repo, user.name = "Alice", user.email = "alice@@example.org") 31##' 32##' ## Create a file, add and commit 33##' lines <- "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do" 34##' writeLines(lines, file.path(path, "test.txt")) 35##' add(repo, "test.txt") 36##' commit(repo, "Commit message 1") 37##' 38##' ## Get the SHA-1 of the last commit 39##' sha(last_commit(repo)) 40##' } 41sha <- function(object) { 42 UseMethod("sha", object) 43} 44 45##' @rdname sha 46##' @export 47sha.git_blob <- function(object) { 48 object$sha 49} 50 51##' @rdname sha 52##' @export 53sha.git_branch <- function(object) { 54 branch_target(object) 55} 56 57##' @rdname sha 58##' @export 59sha.git_commit <- function(object) { 60 object$sha 61} 62 63##' @rdname sha 64##' @export 65sha.git_note <- function(object) { 66 object$sha 67} 68 69##' @rdname sha 70##' @export 71sha.git_reference <- function(object) { 72 object$sha 73} 74 75##' @rdname sha 76##' @export 77sha.git_reflog_entry <- function(object) { 78 object$sha 79} 80 81##' @rdname sha 82##' @export 83sha.git_tag <- function(object) { 84 object$sha 85} 86 87##' @rdname sha 88##' @export 89sha.git_tree <- function(object) { 90 object$sha 91} 92 93##' @rdname sha 94##' @export 95sha.git_fetch_head <- function(object) { 96 object$sha 97} 98 99##' @rdname sha 100##' @export 101sha.git_merge_result <- function(object) { 102 object$sha 103} 104