Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created March 10, 2010 18:21
Show Gist options
  • Save mataspetrikas/328160 to your computer and use it in GitHub Desktop.
Save mataspetrikas/328160 to your computer and use it in GitHub Desktop.
Extracting git information in ActionScript
package com.soundcloud.utils {
import flash.utils.ByteArray;
/**
* @author Matas Petrikas (SoundCloud) matas@soundcloud.com
*
* extract latest Git revision number for later use in AS3
* based on SVNUtil class by Apt labs:
* http://labs.apt.no/2009/11/20/automatically-embedding-a-subversion-revision-number/
*
* Use:
* public static const VERSION:String = GitUtils.version;
* or directly trace(GitUtils.version)
*/
public class GitUtils {
// note, that you might need to adjust this path, depending on your project folder structure
[Embed(source="../../../../.git/refs/heads/master", mimeType="application/octet-stream")]
private static var _entriesByteArray : Class;
public static function get version() : String {
var entries : String = readEntries(40);
return entries;
}
private static function readEntries(length : uint) : String {
return (new _entriesByteArray() as ByteArray).readUTFBytes(length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment