git: Factorize 'resolve-reference'.
* guix/git.scm (resolve-reference): New procedure. (switch-to-ref): Use it.
This commit is contained in:
		
							parent
							
								
									9e0d896bf3
								
							
						
					
					
						commit
						1c058c382a
					
				
					 1 changed files with 42 additions and 37 deletions
				
			
		
							
								
								
									
										13
									
								
								guix/git.scm
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								guix/git.scm
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -150,10 +150,9 @@ of SHA1 string."
 | 
			
		|||
    (last (string-split url #\/)) ".git" "")
 | 
			
		||||
   "-" (string-take sha1 7)))
 | 
			
		||||
 | 
			
		||||
(define (switch-to-ref repository ref)
 | 
			
		||||
  "Switch to REPOSITORY's branch, commit or tag specified by REF.  Return the
 | 
			
		||||
OID (roughly the commit hash) corresponding to REF."
 | 
			
		||||
  (define obj
 | 
			
		||||
(define (resolve-reference repository ref)
 | 
			
		||||
  "Resolve the branch, commit or tag specified by REF, and return the
 | 
			
		||||
corresponding Git object."
 | 
			
		||||
  (let resolve ((ref ref))
 | 
			
		||||
    (match ref
 | 
			
		||||
      (('branch . branch)
 | 
			
		||||
| 
						 | 
				
			
			@ -192,6 +191,12 @@ OID (roughly the commit hash) corresponding to REF."
 | 
			
		|||
         ;; object, whatever that is.
 | 
			
		||||
         (object-lookup repository oid))))))
 | 
			
		||||
 | 
			
		||||
(define (switch-to-ref repository ref)
 | 
			
		||||
  "Switch to REPOSITORY's branch, commit or tag specified by REF.  Return the
 | 
			
		||||
OID (roughly the commit hash) corresponding to REF."
 | 
			
		||||
  (define obj
 | 
			
		||||
    (resolve-reference repository ref))
 | 
			
		||||
 | 
			
		||||
  (reset repository obj RESET_HARD)
 | 
			
		||||
  (object-id obj))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue