diff --git a/how_to/Change_21.md b/how_to/Change_21.md new file mode 100644 index 0000000..2b28be6 --- /dev/null +++ b/how_to/Change_21.md @@ -0,0 +1,23 @@ +- tag: Generalize HEAD to refs + +As part of implementing `tag`, we'll generalize the way we handle HEAD. If you +think about it, HEAD and tags are similar. They are both ways for ugit to attach +a name to an OID. In case of HEAD, the name is hardcoded by ugit; in case of +tags, the name will be provided by the user. It makes sense to handle them +similarly in *data.py*. + +In *data.py*, let's extend the function `set_HEAD` and `get_HEAD` to +`update_ref` and `get_ref`. "Ref" is a short for reference, and that's the name +Git uses. The function will now accept the name of the ref and write/read it as +a file under *.ugit* directory. Logically, a ref is a named pointer to an object. + +The important change is in *data.py*. The rest of the changes just rename some +functions: + +``` +- get_HEAD() -> get_ref('HEAD') +- set_HEAD(oid) -> update_ref('HEAD', oid) +``` + +Note that we didn't change any behaviour of ugit here, this is purely +refactoring.