import 'dart:ffi'; import 'package:ffi/ffi.dart'; import '../util.dart'; import 'libgit2_bindings.dart'; /// Look up the value of one git attribute for path. /// /// Returned value can be either `true`, `false`, `null` (if the attribute was /// not set at all), or a [String] value, if the attribute was set to an actual /// string. Object? getAttribute({ required Pointer repoPointer, required int flags, required String path, required String name, }) { final out = calloc>(); final pathC = path.toNativeUtf8().cast(); final nameC = name.toNativeUtf8().cast(); libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC); calloc.free(pathC); calloc.free(nameC); final attributeValue = libgit2.git_attr_value(out.value); if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_UNSPECIFIED) { calloc.free(out); return null; } if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_TRUE) { calloc.free(out); return true; } if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_FALSE) { calloc.free(out); return false; } if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) { final result = out.value.cast().toDartString(); calloc.free(out); return result; } }