Walk the FETCH_HEAD file with a function.
1 auto repo = initRepo(_userRepo, OpenBare.yes); 2 scope(exit) rmdirRecurse(_userRepo); 3 4 string[] fetchHeadItems = [ 5 "23c3c6add8162693f85b3b41c9bf6550a71a57d3 branch 'master' of git://github.com/D-Programming-Language/dmd\n", 6 "aaf64112624abab1f6cc8f610223f6e12b525e09 branch 'master' of git://github.com/D-Programming-Language/dmd\n" 7 ]; 8 9 std.file.write(buildPath(repo.path, "FETCH_HEAD"), fetchHeadItems.join()); 10 11 static ContinueWalk walkFunc(in char[] refName, in char[] remoteURL, GitOid oid, bool isMerge) 12 { 13 static int count; 14 count++; 15 16 assert(count != 2); // we're stopping after the first iteration 17 18 assert(refName == "refs/heads/master"); 19 assert(remoteURL == "git://github.com/D-Programming-Language/dmd"); 20 assert(oid == GitOid("23C3C6ADD8162693F85B3B41C9BF6550A71A57D3")); 21 22 return ContinueWalk.no; 23 } 24 25 repo.walkFetchHead(&walkFunc);
Walk the FETCH_HEAD file with a delegate.
1 auto repo = initRepo(_userRepo, OpenBare.yes); 2 scope(exit) rmdirRecurse(_userRepo); 3 4 string[] fetchHeadItems = [ 5 "23c3c6add8162693f85b3b41c9bf6550a71a57d3 branch 'master' of git://github.com/D-Programming-Language/dmd\n", 6 "aaf64112624abab1f6cc8f610223f6e12b525e09 branch 'master' of git://github.com/D-Programming-Language/dmd\n" 7 ]; 8 9 std.file.write(buildPath(repo.path, "FETCH_HEAD"), fetchHeadItems.join()); 10 11 struct S 12 { 13 size_t count; 14 15 // delegate walker 16 ContinueWalk walker(in char[] refName, in char[] remoteURL, GitOid oid, bool isMerge) 17 { 18 string line = fetchHeadItems[count++]; 19 string commitHex = line.split[0]; 20 21 assert(refName == "refs/heads/master"); 22 assert(remoteURL == "git://github.com/D-Programming-Language/dmd"); 23 assert(oid == GitOid(commitHex)); 24 25 return ContinueWalk.yes; 26 } 27 28 ~this() 29 { 30 assert(count == 2); // verify we've walked through all the items 31 } 32 } 33 34 S s; 35 repo.walkFetchHead(&s.walker);
Call the callback function for each entry in the FETCH_HEAD file in this repository.
The callback type must be either FetchHeadFunction or FetchHeadDelegate.
This function will return when either all entries are exhausted or when the callback returns ContinueWalk.no.