Projekt OSVED je fenomenalno uspel in je že skoraj končan. Po kratkem dopustu sem po dolgem času spet padel v deep hack mode in tokrat predstavljam en praktičen trik pri raztresenem delu z Git. Enkrat proti koncu zime smo nanj prešli tudi pri GemRB, tako da git-svn ni več potreben.
Dostikrat med delom ugotovim, da je potrebna še kaka druga sprememba in to pred to, na kateri delam. Ali pa da mimogrede odkrijem kakega hrošča. Tako se hitro zgodi, da imam v eni datoteki več nepovezanih sprememb, ki jih zaradi celovitosti potrditve (“commit” ojoj) ni lepo poslati naprej skupaj. Vsak commit naj bi bil zaključena celota, brez nepotrebnih in nepovezanih sprememb. Tako ga je lažje pregledati in tudi iskanje regresij npr. z git-bisect je dosti lažje.
Git zna rešiti tudi ta problem; git-commit moramo le pognati v interaktivnem načinu:
navaden@lynxlynx gemrb 0 $ git commit ––interactive
staged unstaged path
1: unchanged +34/-4 gemrb/core/Actor.cpp
*** Commands ***
1: [s]tatus 2: [u]pdate 3: [r]evert 4: [a]dd untracked
5: [p]atch 6: [d]iff 7: [q]uit 8: [h]elp
What now> 5
Prikaže se nam seznam datotek s spremembami in par možnosti za nadaljevanje. Nas zanima možnost “patch” pod številko 5. Spet se pokaže seznam datotek, mi pa z vnosom njihovih zaporednih številk določimo, na katerih želimo delati. Pred njimi se v seznamu pojavi zvezdica. Ko smo končali z izborom, še enkrat stisnemo enter in že se nam pokaže izpis razlik:
staged unstaged path
1: unchanged +34/-4 [g]emrb/core/Actor.cpp
Patch update>> 1
staged unstaged path
* 1: unchanged +34/-4 [g]emrb/core/Actor.cpp
Patch update>>
diff –git a/gemrb/core/Actor.cpp b/gemrb/core/Actor.cpp
index 8af80a2..4286675 100644
— a/gemrb/core/Actor.cpp
+++ b/gemrb/core/Actor.cpp
@@ -3569,6 +3569,14 @@ const char* Actor::GetScript(int ScriptIndex) const
void Actor::SetModal(ieDword newstate)
{
+/* int off_str = -1;
+ if (off_str != -1 && core->GetStringReference(off_str) != (ieStrRef) -1) {
+ core->DisplayConstantStringName(off_str, 0xffffff, this);
+printf(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaa:%d:\n”, newstate);
+ }*/
+// off_str = STR_HIDENOMORE;
+// off_str = STR_TURNING_OFF;
+// rabmo glede na ModalState, ne glede na newstate!!
switch(newstate) {
case MS_NONE:
break;
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? n
Git gre čez vsak kos sprememb (“patch hunk”) in nas vpraša kaj naj z njim (zadnja vrstica). Kaj pomenijo vse te izbire, nam pove “?”, ampak pomen “y”/”n” je očiten. Očitno je tudi, da je ta kos sprememb le zakomentiran in nesmiselen del nastajajoče kode in nima v končni različici kaj iskati, zato sem izbral “n”.
@@ -3583,12 +3591,27 @@ void Actor::SetModal(ieDword newstate)
default:
return;
}
- //come here only if success
- ModalState = newstate;
- //update the action bar
- if (InParty)
+ // FIXME: check if toggling should work also for npcs
+ if (InParty) {
+ // TODO: display the turning-off message
+ if (ModalState != MS_NONE) {
+ printf(“Turning off state:%d:\n”, ModalState);
+ }
+
+ // when called with the same state twice, toggle to MS_NONE
+ if (ModalState == newstate) {
+ ModalState = MS_NONE;
+ } else {
+ ModalState = newstate;
+ // TODO: display the turning-on message
+ }
+
+ //update the action bar
core->SetEventFlag(EF_ACTION);
+ } else {
+ ModalState = newstate;
+ }
}
//this is just a stub function for now, attackstyle could be melee/ranged
Stage this hunk [y,n,q,a,d,/,K,j,J,g,s,e,?]? y
To je kos, ki sem ga želel potrditi, zato tokrat seveda pride na vrsto izbira “y”.
@@ -3813,6 +3836,11 @@ bool Actor::GetCombatDetails(int &tohit, bool leftorright, WeaponInfo& wi, ITMEx
// ranged – no bonus
}
+ // HACK: Elves get a racial THAC0 bonus with all swords and bows in BG2 (but not daggers); this was hardcoded in IE
+ if (Modified[IE_RACE] == 2) {
+ THAC0Bonus += 1;
+ }
+
//second parameter is left or right hand flag
tohit = GetToHit(THAC0Bonus, Flags);
return true;
Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? n
@@ -4233,6 +4261,8 @@ void Actor::UpdateActorState(ieDword gameTime) {
if (!ModalSpell[0]) {
printMessage(“Actor”,”Modal Spell Effect was not set!\n”, YELLOW);
ModalSpell[0]=’*';
+// } else if(ModalSpell[0]==’-1′) {
+// PerformModalAction(ModalSpell);
} else if(ModalSpell[0]!=’*') {
core->ApplySpell(ModalSpell, this, this, 0);
}
Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n
Še dve nepovezani spremembi. Ker drugih ni bilo več, je git spet prikazal glavni meni:
*** Commands ***
1: [s]tatus 2: [u]pdate 3: [r]evert 4: [a]dd untracked
5: [p]atch 6: [d]iff 7: [q]uit 8: [h]elp
What now> q
Bye.
Tokrat sem izbral izhod in moral takoj vpisat sporočilo ob potrditvi (“commit message”), nakar se je potrditev tudi izvedla:
[master 2a94147] Actor::SetModal now toggles the state to MS_NONE when the new state is the same as the old one, resulting also in proper action bar refreshing.
1 files changed, 19 insertions(+), 4 deletions(-)
Če ste pozabili na kak kos, ponovite postopek, a ko vas vpraša za sporočilo ob spremembi, le zaprite urejevalnik. Kos bo ostal označen kot pripravljen za potrditev (“staged”):
$ git status
# On branch master
# Your branch is ahead of ‘origin/master’ by 1 commit.
#
# Changes to be committed:
# (use “git reset HEAD …” to unstage)
#
# modified: gemrb/core/Actor.cpp
#
# Changed but not updated:
# (use “git add …” to update what will be committed)
# (use “git checkout — …” to discard changes in working directory)
#
# modified: gemrb/core/Actor.cpp
Nato izvedemo le še git commit --amend in zadnji potrditvi bo dodana še ta sprememba, medtem ko bodo druge v isti datoteki lepo ostale kjer so (vidno že iz prejšnjega izpisa).
PS: koda je v resnici prav lepo indentirana, le wordpress je smotan.
Zato sem za lažjo berljivost namesto oznake code uporabil kar blockquote.